コード例 #1
0
ファイル: TripleDESTest.php プロジェクト: horde/horde
 /**
  * @dataProvider engineIVVectors
  */
 public function testVectorsWithIV($engine, $engineName, $key, $iv, $plaintext, $expected)
 {
     $des = new TripleDES();
     if (!$des->isValidEngine($engine)) {
         self::markTestSkipped('Unable to initialize ' . $engineName . ' engine');
     }
     $des->setPreferredEngine($engine);
     $des->setKey($key);
     $des->setIV($iv);
     $des->disablePadding();
     $result = $des->encrypt($plaintext);
     $plaintext = bin2hex($plaintext);
     $this->assertEquals($result, $expected, "Failed asserting that {$plaintext} yielded expected output in {$engineName} engine");
 }
コード例 #2
0
ファイル: Utility.php プロジェクト: camcima/dukpt-php
 /**
  * 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))));
 }