summaryrefslogtreecommitdiff
path: root/plugins/enigma/lib/enigma_driver_gnupg.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/enigma/lib/enigma_driver_gnupg.php')
-rw-r--r--plugins/enigma/lib/enigma_driver_gnupg.php62
1 files changed, 34 insertions, 28 deletions
diff --git a/plugins/enigma/lib/enigma_driver_gnupg.php b/plugins/enigma/lib/enigma_driver_gnupg.php
index 09e23d36c..52a0ad66c 100644
--- a/plugins/enigma/lib/enigma_driver_gnupg.php
+++ b/plugins/enigma/lib/enigma_driver_gnupg.php
@@ -3,18 +3,11 @@
+-------------------------------------------------------------------------+
| GnuPG (PGP) driver for the Enigma Plugin |
| |
- | This program is free software; you can redistribute it and/or modify |
- | it under the terms of the GNU General Public License version 2 |
- | as published by the Free Software Foundation. |
+ | Copyright (C) 2010-2015 The Roundcube Dev Team |
| |
- | This program is distributed in the hope that it will be useful, |
- | but WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- | GNU General Public License for more details. |
- | |
- | You should have received a copy of the GNU General Public License along |
- | with this program; if not, write to the Free Software Foundation, Inc., |
- | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
+ | Licensed under the GNU General Public License version 3 or |
+ | any later version with exceptions for skins & plugins. |
+ | See the README file for a full license statement. |
| |
+-------------------------------------------------------------------------+
| Author: Aleksander Machniak <alec@alec.pl> |
@@ -30,6 +23,7 @@ class enigma_driver_gnupg extends enigma_driver
private $homedir;
private $user;
+
function __construct($user)
{
$this->rc = rcmail::get_instance();
@@ -86,30 +80,40 @@ class enigma_driver_gnupg extends enigma_driver
}
}
+ /**
+ * Encrypt a message
+ *
+ * @param string The message
+ * @param array List of keys
+ */
function encrypt($text, $keys)
{
-/*
- foreach ($keys as $key) {
- $this->gpg->addEncryptKey($key);
+ try {
+ foreach ($keys as $key) {
+ $this->gpg->addEncryptKey($key);
+ }
+
+ $dec = $this->gpg->encrypt($text, true);
+ return $dec;
+ }
+ catch (Exception $e) {
+ return $this->get_error_from_exception($e);
}
- $enc = $this->gpg->encrypt($text);
- return $enc;
-*/
}
/**
- * Register private keys and passwords
+ * Decrypt a message
*
* @param string Encrypted message
* @param array List of key-password mapping
*/
function decrypt($text, $keys = array())
{
- foreach ($keys as $key => $password) {
- $this->gpg->addDecryptKey($key, $password);
- }
-
try {
+ foreach ($keys as $key => $password) {
+ $this->gpg->addDecryptKey($key, $password);
+ }
+
$dec = $this->gpg->decrypt($text);
return $dec;
}
@@ -118,13 +122,15 @@ class enigma_driver_gnupg extends enigma_driver
}
}
- function sign($text, $key, $passwd)
+ function sign($text, $key, $passwd, $mode = null)
{
-/*
- $this->gpg->addSignKey($key, $passwd);
- $signed = $this->gpg->sign($text, Crypt_GPG::SIGN_MODE_DETACHED);
- return $signed;
-*/
+ try {
+ $this->gpg->addSignKey($key, $passwd);
+ return $this->gpg->sign($text, $mode, CRYPT_GPG::ARMOR_ASCII, true);
+ }
+ catch (Exception $e) {
+ return $this->get_error_from_exception($e);
+ }
}
function verify($text, $signature)