You are here

public function EncryptCommands::decrypt in Encrypt 8.3

Decrypt text with the provided encryption profile.

@command encrypt:decrypt @usage drush encrypt:decrypt profile_name 'text to decrypt' Decrypts the given text with the specified encryption profile. @usage drush encrypt:decrypt --base64 profile_name 'text to decrypt' Decrypts the given base64-encoded text with the specified encryption profile. @aliases decrypt,dec

Parameters

string $encryption_profile_name: The machine name of the encryption profile to use.

string $text: The text to encrypt.

array $options: The command options array.

Throws

\Exception

File

src/Commands/EncryptCommands.php, line 88

Class

EncryptCommands
Class EncryptCommands.

Namespace

Drupal\encrypt\Commands

Code

public function decrypt($encryption_profile_name, $text, array $options = [
  'base64' => FALSE,
]) {
  $encryption_profile = EncryptionProfile::load($encryption_profile_name);
  if (!$encryption_profile) {
    throw new \Exception('error', dt('Encryption profile "@name" could not be loaded.', [
      '@name' => $encryption_profile_name,
    ]));
  }
  if ($options['base64']) {
    $text = base64_decode($text);
  }
  $decrypted_text = $this->encrypt
    ->decrypt($text, $encryption_profile);
  $this
    ->output()
    ->writeln($decrypted_text);
}