]> git.mxchange.org Git - friendica-addons.git/blobdiff - securemail/vendor/singpolyma/openpgp-php/lib/openpgp_mcrypt_wrapper.php
securemail: update pgp library
[friendica-addons.git] / securemail / vendor / singpolyma / openpgp-php / lib / openpgp_mcrypt_wrapper.php
diff --git a/securemail/vendor/singpolyma/openpgp-php/lib/openpgp_mcrypt_wrapper.php b/securemail/vendor/singpolyma/openpgp-php/lib/openpgp_mcrypt_wrapper.php
new file mode 100644 (file)
index 0000000..1030700
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+if(function_exists('mcrypt_encrypt') && defined('MCRYPT_MODE_CFB')) {
+  class MCryptWrapper {
+    public $cipher, $key, $iv, $key_size, $block_size;
+
+
+    function __construct($cipher) {
+      $this->cipher = $cipher;
+      $this->key_size = mcrypt_module_get_algo_key_size($cipher);
+      $this->block_size = mcrypt_module_get_algo_block_size($cipher);
+      $this->iv = str_repeat("\0", mcrypt_get_iv_size($cipher, 'ncfb'));
+    }
+
+    function setKey($key) {
+      $this->key = $key;
+    }
+
+    function setIV($iv) {
+      $this->iv = $iv;
+    }
+
+    function encrypt($data) {
+      return mcrypt_encrypt($this->cipher, $this->key, $data, 'ncfb', $this->iv);
+    }
+
+    function decrypt($data) {
+      return mcrypt_decrypt($this->cipher, $this->key, $data, 'ncfb', $this->iv);
+    }
+  }
+}