3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** Aes encryption */ class AES { const M_CBC = 'cbc'; const M_CFB = 'cfb'; const M_ECB = 'ecb'; const M_NOFB = 'nofb'; const M_OFB = 'ofb'; const M_STREAM = 'stream'; protected $key; protected $cipher; protected $data; protected $mode; protected $IV; /** * * @param type $data * @param type $key * @param type $blockSize * @param type $mode */ function __construct($data = null, $key = null, $blockSize = null, $mode = null) { $this->setData($data); $this->setKey($key); $this->setBlockSize($blockSize); $this->setMode($mode); $this->setIV(""); } /** * * @param type $data */ public function setData($data) { $this->data = $data; } /** * * @param type $key */ public function setKey($key) { $this->key = $key; } /** * * @param type $blockSize */ public function setBlockSize($blockSize) { switch ($blockSize) { case 128: $this->cipher = MCRYPT_RIJNDAEL_128; break; case 192: $this->cipher = MCRYPT_RIJNDAEL_192; break; case 256: $this->cipher = MCRYPT_RIJNDAEL_256; break; } } /** * * @param type $mode */ public function setMode($mode) { switch ($mode) { case AES::M_CBC: $this->mode = MCRYPT_MODE_CBC; break; case AES::M_CFB: $this->mode = MCRYPT_MODE_CFB; break; case AES::M_ECB: $this->mode = MCRYPT_MODE_ECB; break; case AES::M_NOFB: $this->mode = MCRYPT_MODE_NOFB; break; case AES::M_OFB: $this->mode = MCRYPT_MODE_OFB; break; case AES::M_STREAM: $this->mode = MCRYPT_MODE_STREAM; break; default: $this->mode = MCRYPT_MODE_ECB; break; } } /** * * @return boolean */ public function validateParams() { if ($this->data != null && $this->key != null && $this->cipher != null) { return true; } else { return FALSE; } } public function setIV($IV) { $this->IV = $IV; } protected function getIV() { if ($this->IV == "") { $this->IV = mcrypt_create_iv(mcrypt_get_iv_size($this->cipher, $this->mode), MCRYPT_RAND); } return $this->IV; } /** * @return type * @throws Exception */ public function encrypt() { if ($this->validateParams()) { return trim(base64_encode( mcrypt_encrypt( $this->cipher, $this->key, $this->data, $this->mode, $this->getIV()))); } else { throw new Exception('Invlid params!'); } } /** * * @return type * @throws Exception */ public function decrypt() { if ($this->validateParams()) { return trim(mcrypt_decrypt( $this->cipher, $this->key, base64_decode($this->data), $this->mode, $this->getIV())); } else { throw new Exception('Invlid params!'); } } } function base16_encode($text) { return bin2hex($text); } function base16_decode($base16){ return pack("H*", $base16); } $key="31323334353637383930393837363534"; $link="62QTUQPXD5PTTmyJPr6wh/b7fdQR94C+MEwg1XEvXI2nV4Lg38yp6AKLW6/ZWW5Z8c+CjfCWZkJoBkpl/p2SS7rp4GAuUR07OKu9rDp/2yoX14y/zx13w62yt6DIRvqWpk/Z4B1EFgSaky6UIHHefubrpnJtAmdq4hhtZXbrNvZvxn6DG74ZJC4B2Qwp3PM1EYz7PiK1MQv2p6dcLdi5J1seJUp9oICdKKYF/hDnNXC6UQSOKz1QDD8oWd4glsp1WGOiR7XXat4llB3g+rZV2suupoR6jpFDAv5DK3GUjEZGUUAgnhNMbHvRVFfce80LOQn7Lh+TUvrXqfE45fzgJcf6qswWHdFCtF8mOUQvjsr67wkkBTn4shNG1bWYF5oXbBOArt+R9dk5IluD2mDGiOj3FymwPQFd+nrHFYIsnSMHs3VC7jpa8nVHo2zYajeXc43dgMiH4mZwfYica1myoKqAfnCpokhaSaOtbE0SKOdhJw2Hw90IChEwvlWFoZmeW1MlA3W9CYIGdR4Xwxl7TXNgw2w9EXwXc0N8WQV1bK7AUB3F722HJMgiLCqjs9UzSTk6yhBs4LNdKnW+F44iQEV7vFibvGVbwanjypxX+E4aydaPPFA3TCpZY+pEo2IY3mfmnH8oyswlp55SvIvLBU4IHNNdfv8ONZzUiasaQSZxQ0K6aVm8nbjUBZEfCX3h5N1h047Vt0sVSI19Bsv9mDzIgXc1jnDREvDdhQM97lzzctm+fyjAPnXmScuqPnhn"; $aes = new AES($link, base16_decode($key), 256, AES::M_CBC); $dec = $aes->decrypt(); echo "Decryption: ".$dec."\r\n";
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Undefined constant "MCRYPT_RIJNDAEL_256" in /in/trE2o:65 Stack trace: #0 /in/trE2o(29): AES->setBlockSize(256) #1 /in/trE2o(167): AES->__construct('62QTUQPXD5PTTmy...', '123456789098765...', 256, 'cbc') #2 {main} thrown in /in/trE2o on line 65
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.82 ms | 401 KiB | 8 Q