mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-18 22:01:30 +00:00
implement basic feed authentication parameter encryption in the database (FEED_CRYPT_KEY)
This commit is contained in:
36
include/crypt.php
Normal file
36
include/crypt.php
Normal file
@@ -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";
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user