diff options
author | Andrew Dolgov <[email protected]> | 2013-05-07 15:36:14 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2013-05-07 15:36:14 +0400 |
commit | 82076ce53113be9cc053f8740356e7e1b81e5643 (patch) | |
tree | 5eba36805f593ec7dd0aad671b5bcca0ae01cf53 /include/crypt.php | |
parent | 66af65f14b4f3c670bb3f9ca7b1c80081f9281d1 (diff) | |
parent | 23923fb29b345c1eea5b70a6df4d30395425bf37 (diff) |
Merge branch 'master' into css-feedtree-counter
Conflicts:
tt-rss.css
Diffstat (limited to 'include/crypt.php')
-rw-r--r-- | include/crypt.php | 36 |
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"; + } +?> |