public function testTripleDesEncryptDecrypt() { $key = '0123456789ABCDEFFEDCBA9876543210'; $data = '0123456789ABCDEF'; $expected = $data; $actual = Utility::tripleDesDecrypt(Utility::tripleDesEncrypt($data, $key), $key, true); $this->assertEquals($expected, $actual); }
public function testDecryptSwipe() { $encryptedData = 'EE83560CE7D7A276196EF815A8E5D58838336A87CE90052B35BE5C78D49BCED40BE2531A3F6FF89E7DFDCF8E73747EEB92712F56CA47CA1A04EB8C41DFDF57C24E4ECF9A1C56C121BE467045CE8DA7EFA6F3D91F65D4247FF8588BE9AE6C082E6BA4A9F03EFDF21B4E4ECF9A1C56C121A37A63AFE2FD0F2B'; $bdk = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; $ksn = new KeySerialNumber('FFFFFFFFFFFFFFE00024'); $expected = '2542343030323437393437303731373439335E4645524E414E44455A2F4D415243555320432020202020205E313330323230313030303030202020202020202030303133363030303030303F3B343030323437393437303731373439333D31333032323031303030303031333630303030303F0000000000'; $derivedKey = DerivedKey::getNowKey($ksn, $bdk); $actual = Utility::tripleDesDecrypt($encryptedData, $derivedKey); $this->assertEquals($expected, $actual); }
public function testDecryptDukptTrack2() { $encryptedHexData = 'AB3B10A3FBC230FBFB941FAC9E82649981AE79F2632156E775A06AEDAFAF6F0A184318C5209E55AD'; $ksn = '62994901190000000002'; $bdk = '0123456789ABCDEFFEDCBA9876543210'; $key = new KeySerialNumber($ksn); $encryptionKey = DerivedKey::calculateDataEncryptionRequestKey($key, $bdk); $actual = Utility::hex2bin(Utility::removePadding(Utility::tripleDesDecrypt($encryptedHexData, $encryptionKey, true))); $expected = ";4266841088889999=080910110000046?0"; $this->assertEquals($expected, $actual); }
/** * 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 \Crypt_TripleDES(CRYPT_DES_MODE_CBC3); // IDTech uses mode CRYPT_DES_MODE_CBC3 } else { $crypt3DES = new \Crypt_TripleDES(CRYPT_DES_MODE_ECB); // Chinese uses mode CRYPT_DES_MODE_ECB } $crypt3DES->setKey(Utility::hex2bin($hexKey)); $crypt3DES->disablePadding(); return strtoupper(bin2hex($crypt3DES->decrypt(Utility::hex2bin($hexEncryptedData)))); }