summaryrefslogtreecommitdiff
path: root/include/crypt.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-04-13 18:24:27 +0400
committerAndrew Dolgov <[email protected]>2013-04-13 18:24:41 +0400
commit044cff2d74ece46256201695346d1a0d1d66c746 (patch)
treef8c4c039e69bde071b74ca27f35839f0a3a55eb7 /include/crypt.php
parent5b27cb05a8af1bcf741a3885b17fc7d03d456c5f (diff)
implement basic feed authentication parameter encryption in the database (FEED_CRYPT_KEY)
Diffstat (limited to 'include/crypt.php')
-rw-r--r--include/crypt.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/include/crypt.php b/include/crypt.php
new file mode 100644
index 000000000..f06483ef1
--- /dev/null
+++ b/include/crypt.php
@@ -0,0 +1,36 @@
+<?php
+ function decrypt_string($str) {
+ $pair = explode(":", $str);
+
+ if (count($pair) == 2) {
+ @$iv = base64_decode($pair[0]);
+ @$encstr = base64_decode($pair[1]);
+
+ if ($iv && $encstr) {
+ $key = hash('SHA256', FEED_CRYPT_KEY, true);
+
+ $str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $encstr,
+ MCRYPT_MODE_CBC, $iv);
+
+ if ($str) return rtrim($str);
+ }
+ }
+
+ return false;
+ }
+
+ function encrypt_string($str) {
+ $key = hash('SHA256', FEED_CRYPT_KEY, true);
+
+ $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,
+ MCRYPT_MODE_CBC), MCRYPT_RAND);
+
+ $encstr = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $str,
+ MCRYPT_MODE_CBC, $iv);
+
+ $iv_base64 = base64_encode($iv);
+ $encstr_base64 = base64_encode($encstr);
+
+ return "$iv_base64:$encstr_base64";
+ }
+?>