public function EncryptCommands::encrypt in Encrypt 8.3
Encrypt text with the provided encryption profile.
@command encrypt:encrypt @option base64 Output the encrypted text in base64 encoded format. @usage drush encrypt:encrypt profile_name 'text to encrypt' Encrypts the given text with the specified encryption profile. @usage drush encrypt:encrypt --base64 profile_name 'text to encrypt' Encrypts the given text with the specified encryption profile and base64-encodes output. @aliases encrypt,enc
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 54
Class
- EncryptCommands
- Class EncryptCommands.
Namespace
Drupal\encrypt\CommandsCode
public function encrypt($encryption_profile_name, $text, array $options = [
'base64' => FALSE,
]) {
$encryption_profile = EncryptionProfile::load($encryption_profile_name);
if (!$encryption_profile) {
throw new \Exception(dt("Encryption profile @profile could not be loaded.", [
'@profile' => $encryption_profile,
]));
}
$encrypted_text = $this->encrypt
->encrypt($text, $encryption_profile);
if ($options['base64']) {
$encrypted_text = base64_encode($encrypted_text);
}
$this
->output()
->writeln($encrypted_text);
}