3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Emulate OpenFire Blowfish Class */ class OpenFireBlowfish { private $key; private $cipher; public $enckey = "70S28ao84z4wGS7"; //Hidden Encryption Key of Openfire BlowFish public $enciv = ''; function __construct($pass) { $this->cipher = mcrypt_module_open('blowfish','','cbc',''); $ks = mcrypt_enc_get_key_size($this->cipher); $this->key = pack('H*',sha1($pass)); } function encryptString($plaintext, $iv = '') { if ($iv == '') { $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->cipher)); } else { $iv = pack("H*", $iv); } mcrypt_generic_init($this->cipher, $this->key, $iv); $bs = mcrypt_enc_get_block_size($this->cipher); // get block size $plaintext = mb_convert_encoding($plaintext,'UTF-16BE'); // set to 2 byte, network order $pkcs = $bs - (strlen($plaintext) % $bs); // get pkcs5 pad length $pkcs = str_repeat(chr($pkcs), $pkcs); // create padding string $plaintext = $plaintext.$pkcs; // append pkcs5 padding to the data $result = mcrypt_generic($this->cipher, $plaintext); mcrypt_generic_deinit($this->cipher); return $iv.$result; } function decryptString($ciphertext) { $bs = mcrypt_enc_get_block_size($this->cipher); // get block size $iv_size = mcrypt_enc_get_iv_size($this->cipher); if ((strlen($ciphertext) % $bs) != 0) { // check string is proper size exit(1); } $iv = substr($ciphertext, 0, $iv_size); // retrieve IV $ciphertext = substr($ciphertext, $iv_size); mcrypt_generic_init($this->cipher, $this->key, $iv); $result = mdecrypt_generic($this->cipher, $ciphertext); // decrypt //echo var_dump(unpack('c*',$iv))."\n"; $padding = ord(substr($result,-1)); // retrieve padding $result = substr($result,0,$padding * -1); // and remove it mcrypt_generic_deinit($this->cipher); return $result; } function __destruct() { mcrypt_module_close($this->cipher); } } // Test OpenFire Blowfish Class $enckey = "70S28ao84z4wGS7"; //paste your openfire Db passwordKey copied in poin# 3 $enciv = ''; $a = new OpenFireBlowfish($enckey); $encstring = bin2hex($a->encryptString('password',$enciv)); //enter your password string to encrypt it echo "Encrypted Password string:".$encstring . "<br>"; echo "Original Password string:".$a->decryptString(pack("H*", $encstring)) . "<br>"; ?>
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Call to undefined function mcrypt_module_open() in /in/4EfMO:18 Stack trace: #0 /in/4EfMO(75): OpenFireBlowfish->__construct('70S28ao84z4wGS7') #1 {main} thrown in /in/4EfMO on line 18
Process exited with code 255.
Output for 5.1.3 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Call to undefined function mcrypt_module_open() in /in/4EfMO on line 18
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.2
Fatal error: Call to undefined function mcrypt_module_open() in /in/4EfMO on line 18 Fatal error: Call to undefined function mcrypt_module_close() in /in/4EfMO on line 65
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/4EfMO on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/4EfMO on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/4EfMO on line 9
Process exited with code 255.

preferences:
353.67 ms | 401 KiB | 459 Q