You are here

public static function LockrAes256CbcSha256RawKeyWrapper::decrypt in Lockr 7.3

Decrypt the given ciphertext.

Parameters

string $ciphertext:

string $wrapping_key:

Return value

string|bool

Overrides KeyWrapperInterface::decrypt

3 calls to LockrAes256CbcSha256RawKeyWrapper::decrypt()
LockrAes256CbcSha256KeyWrapper::decrypt in vendor/lockr/lockr/src/KeyWrapper/LockrAes256CbcSha256KeyWrapper.php
Decrypt the given ciphertext.
LockrAes256CbcSha256RawKeyWrapperTest::testEncryptsData in vendor/lockr/lockr/tests/KeyWrapper/LockrAes256CbcSha256RawKeyWrapperTest.php
LockrAes256CbcSha256RawKeyWrapperTest::testReencryptsData in vendor/lockr/lockr/tests/KeyWrapper/LockrAes256CbcSha256RawKeyWrapperTest.php

File

vendor/lockr/lockr/src/KeyWrapper/LockrAes256CbcSha256RawKeyWrapper.php, line 46

Class

LockrAes256CbcSha256RawKeyWrapper

Namespace

Lockr\KeyWrapper

Code

public static function decrypt($ciphertext, $wrapping_key) {
  $wrapping_key = substr($wrapping_key, strlen(self::PREFIX));
  $wrapping_key = base64_decode($wrapping_key);
  $key_data = hash('sha512', $wrapping_key, true);
  $enc_key = substr($key_data, 0, self::KEY_LEN);
  $hmac_key = substr($key_data, self::KEY_LEN);
  $iv = substr($ciphertext, 0, self::IV_LEN);
  $hmac0 = substr($ciphertext, -self::HMAC_KEY_LEN);
  $ciphertext = substr($ciphertext, self::IV_LEN, -self::HMAC_KEY_LEN);
  $hmac1 = self::hmac($iv, $ciphertext, $hmac_key);
  if (!hash_equals($hmac0, $hmac1)) {
    return false;
  }
  $plaintext = openssl_decrypt($ciphertext, self::METHOD, $enc_key, OPENSSL_RAW_DATA, $iv);
  if ($plaintext === false) {
    return false;
  }
  return $plaintext;
}