-
Notifications
You must be signed in to change notification settings - Fork 12
/
test.php
55 lines (44 loc) · 1.2 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
52
53
54
55
<?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\PBEWithMD5AndDES::encrypt(
$data,
$keyString,
$salt,
$iterations,
$segments
);
$decrypt = PBEWithMD5AndDES\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;
$crypt = PBEWithMD5AndDES\PBEWithMD5AndDES::encrypt(
$data,
$keyString
);
$decrypt = PBEWithMD5AndDES\PBEWithMD5AndDES::decrypt(
$crypt,
$keyString
);
echo "Plain text data: $data" . PHP_EOL;
echo "Key string: $keyString" . PHP_EOL;
echo "Crypt data: $crypt" . PHP_EOL;
echo "Decrypted data: $decrypt" . PHP_EOL;
echo PHP_EOL;
echo "Check it with openssl command:" . PHP_EOL
. "echo '$crypt' | openssl enc -des -a -d -k '$keyString'" . PHP_EOL;