You are here

public static function LockrAes256CbcSha256KeyWrapper::decrypt in Lockr 7.3

Same name and namespace in other branches
  1. 7.2 vendor/lockr/lockr-client/src/KeyWrapper/LockrAes256CbcSha256KeyWrapper.php \Lockr\KeyWrapper\LockrAes256CbcSha256KeyWrapper::decrypt()

Decrypt the given ciphertext.

Parameters

string $ciphertext:

string $wrapping_key:

Return value

string|bool

Overrides KeyWrapperInterface::decrypt

3 calls to LockrAes256CbcSha256KeyWrapper::decrypt()
LockrAes256CbcSha256KeyWrapperTest::testEncryptsData in vendor/lockr/lockr/tests/KeyWrapper/LockrAes256CbcSha256KeyWrapperTest.php
LockrAes256CbcSha256KeyWrapperTest::testReencryptsData in vendor/lockr/lockr/tests/KeyWrapper/LockrAes256CbcSha256KeyWrapperTest.php
LockrAes256CbcSha256KeyWrapperTest::testUpgradedData in vendor/lockr/lockr/tests/KeyWrapper/LockrAes256CbcSha256KeyWrapperTest.php

File

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

Class

LockrAes256CbcSha256KeyWrapper

Namespace

Lockr\KeyWrapper

Code

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