You are here

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

Class

ConfigTestEncryptionMethod
ConfigTestEncryptionMethod testing class.

Namespace

Drupal\encrypt_test\Plugin\EncryptionMethod

Code

public function decrypt($text, $key, $options = []) {
  $decoded = str_rot13($text);
  $prefix = $key . $this
    ->getConfiguration()['mode'];

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