You are here

function drush_encrypt_decrypt in Encrypt 8.3

Decrypt text with the given encryption profile.

Parameters

string $encryption_profile_name: The encryption profile machine name.

string $text: The text to decrypt.

Return value

string The decrypted text.

File

drush/encrypt.drush.inc, line 126
Drush integration for Encrypt module.

Code

function drush_encrypt_decrypt($encryption_profile_name = FALSE, $text = FALSE) {
  if ($encryption_profile_name && $text) {
    $service = \Drupal::service('encryption');
    $encryption_profile = EncryptionProfile::load($encryption_profile_name);
    if (!$encryption_profile) {
      return drush_set_error('error', dt('Encryption profile "@name" could not be loaded.', [
        '@name' => $encryption_profile_name,
      ]));
    }
    else {
      if (drush_get_option('base64')) {
        $text = base64_decode($text);
      }
      $decrypted_text = $service
        ->decrypt($text, $encryption_profile);
      drush_print($decrypted_text);
    }
  }
  else {
    return drush_set_error('error', dt('Please specify the decryption profile and the encrypted text to be decrypted', []));
  }
}