You are here

public function TestEncryptionMethod::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/TestEncryptionMethod.php, line 38

Class

TestEncryptionMethod
TestEncryptionMethod testing class.

Namespace

Drupal\encrypt_test\Plugin\EncryptionMethod

Code

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

  // Strip out key, to retrieve original text.
  if (substr($decoded, 0, strlen($key)) == $key) {
    return substr($decoded, strlen($key));
  }
  else {
    return "invalid key";
  }
}