/** * 3-DES Decrypt in EDE-CBC3 Mode * * @param string $hexEncryptedData * Encrypted Data in hexadecimal representation * @param string $hexKey * Key in hexadecimal representation * @param bool $useDesModeCBC3 * Use DES CBC3 Mode * * @return string * Decrypted data in hexadecimal representation */ public static function tripleDesDecrypt($hexEncryptedData, $hexKey, $useDesModeCBC3 = false) { //fix Crypt Library padding $hexKey = $hexKey . substr($hexKey, 0, 16); if ($useDesModeCBC3) { $crypt3DES = new TripleDES(TripleDES::MODE_CBC3); // IDTech uses mode CRYPT_DES_MODE_CBC3 } else { $crypt3DES = new TripleDES(TripleDES::MODE_ECB); // Chinese uses mode CRYPT_DES_MODE_ECB } $crypt3DES->setKey(Utility::hex2bin($hexKey)); $crypt3DES->disablePadding(); return strtoupper(bin2hex($crypt3DES->decrypt(Utility::hex2bin($hexEncryptedData)))); }