Horde_Crypt_Pgp::encrypt PHP Method

encrypt() public method

Encrypts text using PGP.
public encrypt ( string $text, array $params = [] ) : string
$text string The text to be PGP encrypted.
$params array The parameters needed for encryption. See the individual _encrypt*() functions for the parameter requirements.
return string The encrypted message.
    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);
    }