Esempio n. 1
0
 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);
 }
Esempio n. 2
0
 /**
  * 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))));
 }