forked from kevinsandow/PBEWithMD5AndDES
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
51 lines (38 loc) · 1.12 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
require_once 'PkcsKeyGenerator.php';
require_once 'DesEncryptor.php';
require_once 'PbeWithMd5AndDes.php';
$salt = 'abcdef1234567890';
$iterations = 20;
$segments = 1;
$data = 'Hello World!';
$keystring = 'secret';
$crypt = PbeWithMd5AndDes::encrypt(
$data, $keystring,
$salt, $iterations, $segments
);
$decrypt = PbeWithMd5AndDes::decrypt(
$crypt, $keystring,
$salt, $iterations, $segments
);
echo "Plain text data: $data" . PHP_EOL;
echo "Key string: $keystring" . PHP_EOL;
echo "Salt: $salt" . PHP_EOL;
echo "Crypt data: $crypt" . PHP_EOL;
echo "Decripted data: $decrypt" . PHP_EOL;
echo PHP_EOL . "== Use random salt ==" . PHP_EOL;
$data = 'Hello World!';
$keystring = 'secret';
$crypt = PbeWithMd5AndDes::encrypt(
$data, $keystring
);
$decrypt = PbeWithMd5AndDes::decrypt(
$crypt, $keystring
);
echo "Plain text data: $data" . PHP_EOL;
echo "Key string: $keystring" . PHP_EOL;
echo "Crypt data: $crypt" . PHP_EOL;
echo "Decripted data: $decrypt" . PHP_EOL;
echo PHP_EOL;
echo "Check it with openssl command: echo '$crypt' | openssl enc -des -a -d -k '$keystring'" . PHP_EOL;
?>