-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
28 lines (20 loc) · 873 Bytes
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
function encrypt($string = '', $key = '') {
$key = utf8_encode($key);
//make it 32 chars long. pad with \0 for shorter keys
$key = str_pad($key, 32, "\0");
//make the input string length multiples of 16. This is necessary
$padding = 16 - (strlen($string) % 16);
$string .= str_repeat(chr($padding), $padding);
//emtpy IV - initialization vector
$iv = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_MODE_CBC, $iv));
return rtrim($encrypted);
}
function decrypt($string = '', $key = '') {
$key = $key . "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
$iv = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
$string = base64_decode($string);
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_MODE_CBC, $iv);
}
echo encrypt('123456');