You are here

public function AsymmetricalEncryptionMethod::decrypt in Encrypt 8.3

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

tests/modules/encrypt_test/src/Plugin/EncryptionMethod/AsymmetricalEncryptionMethod.php, line 40

Class

AsymmetricalEncryptionMethod
Encryption-only encryption method, it can NOT decrypt.

Namespace

Drupal\encrypt_test\Plugin\EncryptionMethod

Code

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

  // This method should throw EncryptionMethodCanNotDecryptException, however
  // if we do it here from the test we won't be able to understand if the
  // exception is thrown by the 'encryption' service or by this method. In a
  // normal scenario method with 'can_decrypt' FALSE can and should throw
  // EncryptionMethodCanNotDecryptException.
  throw new AsymmetricalEncryptionMethodCanNotDecryptException();
}