]> git.wh0rd.org Git - tt-rss.git/blob - include/crypt.php
Updater: check whether system() is useable.
[tt-rss.git] / include / crypt.php
1 <?php
2         function decrypt_string($str) {
3                 $pair = explode(":", $str);
4
5                 if (count($pair) == 2) {
6                         @$iv = base64_decode($pair[0]);
7                         @$encstr = base64_decode($pair[1]);
8
9                         if ($iv && $encstr) {
10                                 $key = hash('SHA256', FEED_CRYPT_KEY, true);
11
12                                 $str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $encstr,
13                                         MCRYPT_MODE_CBC, $iv);
14
15                                 if ($str) return rtrim($str);
16                         }
17                 }
18
19                 return false;
20         }
21
22         function encrypt_string($str) {
23                 $key = hash('SHA256', FEED_CRYPT_KEY, true);
24
25                 $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,
26                         MCRYPT_MODE_CBC), MCRYPT_RAND);
27
28                 $encstr = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $str,
29                         MCRYPT_MODE_CBC, $iv);
30
31                 $iv_base64 = base64_encode($iv);
32                 $encstr_base64 = base64_encode($encstr);
33
34                 return "$iv_base64:$encstr_base64";
35         }
36 ?>