Наследование: extends phpseclib\Crypt\Common\BlockCipher
Пример #1
0
 /**
  * @dataProvider engineVectors
  */
 public function testVectors($engine, $engineName, $key, $keyLen, $plaintext, $ciphertext)
 {
     $rc2 = new RC2();
     $rc2->disablePadding();
     $rc2->setKeyLength($keyLen);
     $rc2->setKey(pack('H*', $key));
     // could also do $rc2->setKey(pack('H*', $key), $keyLen)
     if (!$rc2->isValidEngine($engine)) {
         self::markTestSkipped('Unable to initialize ' . $engineName . ' engine');
     }
     $rc2->setPreferredEngine($engine);
     $result = bin2hex($rc2->encrypt(pack('H*', $plaintext)));
     $this->assertEquals($result, $ciphertext, "Failed asserting that {$plaintext} yielded expected output in {$engineName} engine");
 }
Пример #2
0
 /**
  * Returns a SymmetricKey object baesd on a PBES2 $algo
  *
  * @access public
  * @param string $algo
  */
 static function getPBES2EncryptionObject($algo)
 {
     switch ($algo) {
         case 'desCBC':
             $cipher = new TripleDES(BlockCipher::MODE_CBC);
             break;
         case 'des-EDE3-CBC':
             $cipher = new TripleDES(BlockCipher::MODE_CBC);
             break;
         case 'rc2CBC':
             $cipher = new RC2(BlockCipher::MODE_CBC);
             // in theory this can be changed
             $cipher->setKeyLength(128);
             break;
         case 'rc5-CBC-PAD':
             throw new UnsupportedAlgorithmException('rc5-CBC-PAD is not supported for PBES2 PKCS#8 keys');
         case 'aes128-CBC-PAD':
         case 'aes192-CBC-PAD':
         case 'aes256-CBC-PAD':
             $cipher = new AES(BlockCipher::MODE_CBC);
             $cipher->setKeyLength(substr($algo, 3, 3));
             break;
         default:
             throw new UnsupportedAlgorithmException("{$algo} is not supported");
     }
     return $cipher;
 }