public function encrypt($text, $params = array())
{
switch (isset($params['type']) ? $params['type'] : false) {
case 'message':
$error = Horde_Crypt_Translation::t("Could not PGP encrypt message.");
$func = 'encryptMessage';
break;
case 'signature':
/* Check for required parameters. */
if (!isset($params['pubkey']) || !isset($params['privkey']) || !isset($params['passphrase'])) {
/* This is a programming error, not a user displayable
* error. */
throw new InvalidArgumentException('A public PGP key, private PGP key, and passphrase are required to sign a message.');
}
$error = Horde_Crypt_Translation::t("Could not PGP sign message.");
$func = 'encryptSignature';
break;
default:
throw new InvalidArgumentException('Incorrect "type" parameter provided.');
}
$this->_initDrivers();
foreach ($this->_backends as $val) {
try {
return $val->{$func}($text, $params);
} catch (Horde_Crypt_Exception $e) {
}
}
throw new Horde_Crypt_Exception($error);
}