legacyDecrypt() 공개 정적인 메소드

Decrypts a legacy ciphertext produced by version 1 of this library.
public static legacyDecrypt ( string $ciphertext, string $key ) : string
$ciphertext string
$key string
리턴 string
예제 #1
0
 /**
  * 1. VerifyHMAC-then-Decrypt the ciphertext to get the hash
  * 2. Verify that the password matches the hash
  *
  * @param string $password
  * @param string $ciphertext
  * @param string $aesKey - must be exactly 16 bytes
  * @return boolean
  */
 public static function decryptAndVerifyLegacy($password, $ciphertext, $aesKey)
 {
     if (self::safeStrlen($aesKey) !== 16) {
         throw new \Exception("Encryption keys must be 16 bytes long");
     }
     $hash = Crypto::legacyDecrypt($ciphertext, $aesKey);
     return \password_verify(\base64_encode(\hash('sha256', $password, true)), $hash);
 }
예제 #2
0
 /**
  * Decrypts data
  *
  * @param string $data The data to encrypt
  *
  * @return string The encrypted data
  *
  * @throws \CodeCollab\Encryption\CryptoException When the message could not be decrypted
  * @throws \CodeCollab\Encryption\FraudException  When the message is potentially tampered with
  */
 public function decrypt(string $data) : string
 {
     try {
         return Crypto::legacyDecrypt($data, $this->key);
     } catch (WrongKeyOrModifiedCiphertextException $e) {
         throw new FraudException($e->getMessage(), $e->getCode(), $e);
     } catch (EnvironmentIsBrokenException $e) {
         throw new CryptoException($e->getMessage(), $e->getCode(), $e);
     }
 }
예제 #3
0
 /**
  * For migrating from an older version of the library
  *
  * @param string $password
  * @param string $ciphertext
  * @param string $oldKey
  * @param Key $newKey
  * @return string
  * @throws \Exception
  */
 public static function upgradeFromVersion1(string $password, string $ciphertext, string $oldKey, Key $newKey) : string
 {
     if (!self::decryptAndVerifyLegacy($password, $ciphertext, $oldKey)) {
         throw new \Exception('The correct password is necessary for legacy migration.');
     }
     $plaintext = Crypto::legacyDecrypt($ciphertext, $oldKey);
     return self::hashAndEncrypt($plaintext, $newKey);
 }
예제 #4
0
 /**
  * @expectedException \Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException
  */
 public function testDecryptLegacyCiphertextWrongKey()
 {
     $cipher = Encoding::hexToBin('cfdad83ebd506d2c9ada8d48030d0bca' . '2ff94760e6d39c186adb1290d6c47e35' . '821e262673c5631c42ebbaf70774d6ef' . '29aa5eee0e412d646ae380e08189c85d' . '024b5e2009106870f1db25d8b85fd01f');
     $plain = Crypto::legacyDecrypt($cipher, "\t\n\v\f\r");
 }