You are here

public static function LockrAes128CtrSha256KeyWrapper::decrypt in Lockr 7.2

Same name and namespace in other branches
  1. 7.3 vendor/lockr/lockr/src/KeyWrapper/LockrAes128CtrSha256KeyWrapper.php \Lockr\KeyWrapper\LockrAes128CtrSha256KeyWrapper::decrypt()

Decrypt the given ciphertext using encoded.

Parameters

string $ciphertext:

string $encoded:

Return value

string|bool

Overrides KeyWrapperInterface::decrypt

File

vendor/lockr/lockr-client/src/KeyWrapper/LockrAes128CtrSha256KeyWrapper.php, line 55

Class

LockrAes128CtrSha256KeyWrapper

Namespace

Lockr\KeyWrapper

Code

public static function decrypt($ciphertext, $encoded) {
  $parts = self::decode($encoded);
  if (!$parts) {
    return false;
  }
  list($key, $iv, $hmac_key) = $parts;
  $hmac = base64_decode(substr($ciphertext, 0, self::HASH_BYTES));
  $ciphertext = base64_decode(substr($ciphertext, self::HASH_BYTES));
  if (!self::hashEquals($hmac, self::hmac($ciphertext, $hmac_key))) {
    return false;
  }
  $plaintext = openssl_decrypt($ciphertext, self::METHOD, $key, OPENSSL_RAW_DATA, $iv);
  if ($plaintext === false) {
    return false;
  }
  return $plaintext;
}