decryptAndVerify() public static method

1. VerifyHMAC-then-Decrypt the ciphertext to get the hash 2. Verify that the password matches the hash
public static decryptAndVerify ( string $password, string $ciphertext, Defuse\Crypto\Key $aesKey ) : boolean
$password string
$ciphertext string
$aesKey Defuse\Crypto\Key
return boolean
 /**
  * @expectedException \Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException
  */
 public function testBitflip()
 {
     $key = Key::createNewRandomKey();
     $password = PasswordLock::hashAndEncrypt('YELLOW SUBMARINE', $key);
     $password[0] = \ord($password[0]) === 0 ? 255 : 0;
     PasswordLock::decryptAndVerify('YELLOW SUBMARINE', $password, $key);
 }
 /**
  * @expectedException \Defuse\Crypto\Exception\InvalidCiphertext
  */
 public function testBitflip()
 {
     $key = \Defuse\Crypto\Key::LoadFromAsciiSafeString(\hex2bin('0102030405060708090a0b0c0d0e0f10'));
     $password = PasswordLock::hashAndEncrypt('YELLOW SUBMARINE', $key);
     $password[0] = \ord($password[0]) === 0 ? 255 : 0;
     PasswordLock::decryptAndVerify('YELLOW SUBMARINE', $password, $key);
 }
 /**
  * @expectedException \Defuse\Crypto\Exception\InvalidCiphertext
  */
 public function testBitflip()
 {
     $key = \hex2bin('0102030405060708090a0b0c0d0e0f10');
     $password = PasswordLock::hashAndEncrypt('YELLOW SUBMARINE', $key);
     $password[0] = \ord($password[0]) === 0 ? 255 : 0;
     PasswordLock::decryptAndVerify('YELLOW SUBMARINE', $password, $key);
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function verify(string $password, string $hashedValue) : bool
 {
     return PasswordLock::decryptAndVerify($password, $hashedValue, $this->key);
 }