You are here

public function RealAESEncryptionMethod::decrypt in Real AES 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/EncryptionMethod/RealAESEncryptionMethod.php \Drupal\real_aes\Plugin\EncryptionMethod\RealAESEncryptionMethod::decrypt()

Decrypt text.

Parameters

string $text: The text to be decrypted.

string $key: The key to decrypt the text with.

Return value

string The decrypted text

Throws

\Drupal\encrypt\Exception\EncryptException Thrown when decryption fails.

\Drupal\encrypt\Exception\EncryptionMethodCanNotDecryptException The method should throw this exception when the plugin can not decrypt (i.e. use a public key).

Overrides EncryptionMethodInterface::decrypt

File

src/Plugin/EncryptionMethod/RealAESEncryptionMethod.php, line 61

Class

RealAESEncryptionMethod
Class RealAESEncryptionMethod.

Namespace

Drupal\real_aes\Plugin\EncryptionMethod

Code

public function decrypt($text, $key, $options = []) {
  try {

    // Defuse PHP-Encryption requires a key object instead of a string.
    $key = Encoding::saveBytesToChecksummedAsciiSafeString(Key::KEY_CURRENT_VERSION, $key);
    $key = Key::loadFromAsciiSafeString($key);
    return Crypto::decrypt((string) $text, $key);
  } catch (Ex\CryptoException $ex) {
    return FALSE;
  }
}