From 0d9d576aa642e02eb8673aa20bdf4b6a18ae6bc3 Mon Sep 17 00:00:00 2001 From: Friendika Date: Sat, 20 Aug 2011 04:53:11 -0700 Subject: [PATCH] move encryption functions to crypto file --- include/crypto.php | 42 +++++++++++++++++++++++++++++++++++++++++- include/diaspora.php | 1 + include/items.php | 5 +++-- include/text.php | 40 ---------------------------------------- include/zotfns.php | 2 ++ 5 files changed, 47 insertions(+), 43 deletions(-) diff --git a/include/crypto.php b/include/crypto.php index 6b27e832bd..999b48be4d 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -74,7 +74,7 @@ function DerToRsa($Der) //Encode: $Der = base64_encode($Der); //Split lines: - $lines = str_split($Der, 65); + $lines = str_split($Der, 64); $body = implode("\n", $lines); //Get title: $title = 'RSA PUBLIC KEY'; @@ -184,3 +184,43 @@ function salmon_key($pubkey) { } + +if(! function_exists('aes_decrypt')) { +function aes_decrypt($val,$ky) +{ + $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + for($a=0;$a=0 and ord(substr($dec, strlen($dec)-1,1))<=16)? chr(ord( substr($dec,strlen($dec)-1,1))):null)); +}} + + +if(! function_exists('aes_encrypt')) { +function aes_encrypt($val,$ky) +{ + $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + for($a=0;$a strlen($text)) return false; + if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false; + return substr($text, 0, -1 * $pad); +} diff --git a/include/diaspora.php b/include/diaspora.php index 2e8ff6892c..a52c82913d 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -141,6 +141,7 @@ function diaspora_decode($importer,$xml) { $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $outer_key, $ciphertext, MCRYPT_MODE_CBC, $outer_iv); + $decrypted = pkcs5_unpad($decrypted); /** diff --git a/include/items.php b/include/items.php index 39a61c4ad0..b84b71ba80 100644 --- a/include/items.php +++ b/include/items.php @@ -1,8 +1,9 @@ =0 and ord(substr($dec, strlen($dec)-1,1))<=16)? chr(ord( substr($dec,strlen($dec)-1,1))):null)); -}} - - -if(! function_exists('aes_encrypt')) { -function aes_encrypt($val,$ky) -{ - $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; - for($a=0;$a strlen($text)) return false; - if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false; - return substr($text, 0, -1 * $pad); -} - function base64url_encode($s, $strip_padding = false) { diff --git a/include/zotfns.php b/include/zotfns.php index b695b6fcb6..b23fce82a5 100644 --- a/include/zotfns.php +++ b/include/zotfns.php @@ -2,6 +2,8 @@ require_once('include/salmon.php'); +require_once('include/crypto.php'); + function zot_get($url,$args) { $argstr = '';