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*", "f84cbd64e079a04c0c9368937702d70251a06e7e86852429cfda6235e391febe")) . "<br>"; ?>
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.33, 7.4.3 - 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/SUWCJ:18 Stack trace: #0 /in/SUWCJ(75): OpenFireBlowfish->__construct('70S28ao84z4wGS7') #1 {main} thrown in /in/SUWCJ on line 18
Process exited with code 255.
Output for 5.4.45
Encrypted Password string:7252e31c9e3663a2a73718487bbfa5d1ce711c5221dbdb50832f032c4bd7e0c6<br>Original Password string:DredZyt7<br>
Output for 5.4.44
Encrypted Password string:faf1c0666e2f70300f7e4c849bf1524649356cd560ab1b107358c9491294f2d2<br>Original Password string:DredZyt7<br>
Output for 5.4.43
Encrypted Password string:3208a9cb903efda5b51d0f35fff14a03cfd9f5eac53c1ef333b78bb2ba28343a<br>Original Password string:DredZyt7<br>
Output for 5.4.34 - 5.4.42

Process exited with code 137.
Output for 5.4.0 - 5.4.32
Fatal error: Call to undefined function mcrypt_module_open() in /in/SUWCJ on line 18
Process exited with code 255.

preferences:
151.51 ms | 401 KiB | 184 Q