ParagonIE\PasswordLock\PasswordLock::decryptAndVerify PHP Method

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
    public static function decryptAndVerify(string $password, string $ciphertext, Key $aesKey) : bool
    {
        if (!\is_string($password)) {
            throw new \InvalidArgumentException('Password must be a string.');
        }
        if (!\is_string($ciphertext)) {
            throw new \InvalidArgumentException('Ciphertext must be a string.');
        }
        $hash = Crypto::decrypt($ciphertext, $aesKey);
        return \password_verify(Base64::encode(\hash('sha384', $password, true)), $hash);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @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);
 }
All Usage Examples Of ParagonIE\PasswordLock\PasswordLock::decryptAndVerify