aboutsummaryrefslogtreecommitdiffstats
path: root/include/crypto.php
diff options
context:
space:
mode:
authorFriendika <info@friendika.com>2011-08-20 04:53:11 -0700
committerFriendika <info@friendika.com>2011-08-20 04:53:11 -0700
commit0d9d576aa642e02eb8673aa20bdf4b6a18ae6bc3 (patch)
treecf41c9c4bc72a345f8a05896b82d54c06074dbf0 /include/crypto.php
parent6aa633efc829d4d3e9ccba4f6fb4d555f3c968ca (diff)
downloadvolse-hubzilla-0d9d576aa642e02eb8673aa20bdf4b6a18ae6bc3.tar.gz
volse-hubzilla-0d9d576aa642e02eb8673aa20bdf4b6a18ae6bc3.tar.bz2
volse-hubzilla-0d9d576aa642e02eb8673aa20bdf4b6a18ae6bc3.zip
move encryption functions to crypto file
Diffstat (limited to 'include/crypto.php')
-rw-r--r--include/crypto.php42
1 files changed, 41 insertions, 1 deletions
diff --git a/include/crypto.php b/include/crypto.php
index 6b27e832b..999b48be4 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<strlen($ky);$a++)
+ $key[$a%16]=chr(ord($key[$a%16]) ^ ord($ky[$a]));
+ $mode = MCRYPT_MODE_ECB;
+ $enc = MCRYPT_RIJNDAEL_128;
+ $dec = @mcrypt_decrypt($enc, $key, $val, $mode, @mcrypt_create_iv( @mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM ) );
+ return rtrim($dec,(( ord(substr($dec,strlen($dec)-1,1))>=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($ky);$a++)
+ $key[$a%16]=chr(ord($key[$a%16]) ^ ord($ky[$a]));
+ $mode=MCRYPT_MODE_ECB;
+ $enc=MCRYPT_RIJNDAEL_128;
+ $val=str_pad($val, (16*(floor(strlen($val) / 16)+(strlen($val) % 16==0?2:1))), chr(16-(strlen($val) % 16)));
+ return mcrypt_encrypt($enc, $key, $val, $mode, mcrypt_create_iv( mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM));
+}}
+
+
+function pkcs5_pad ($text, $blocksize)
+{
+ $pad = $blocksize - (strlen($text) % $blocksize);
+ return $text . str_repeat(chr($pad), $pad);
+}
+
+function pkcs5_unpad($text)
+{
+ $pad = ord($text{strlen($text)-1});
+ if ($pad > strlen($text)) return false;
+ if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false;
+ return substr($text, 0, -1 * $pad);
+}