-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_aes.php
58 lines (47 loc) · 1.77 KB
/
test_aes.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
56
<?php
/**
* Created by PhpStorm.
* User: 沧澜
* Date: 2019-05-23
* Annotation:
*/
use CalJect\Encryption\Constants\Openssl;
use CalJect\Encryption\Encryption;
require "../vendor/autoload.php";
/**
* 使用其他加密模式
* @see Openssl
* @see openssl_get_cipher_methods()
*/
$key = 'R09w0jmo';
/* ======== coding with Base64 ======== */
// $aes = AesFactory::createAesEcb128($key);
// $aes = Encryption::$aes::createAes($key, Openssl::CODING_BASE64, 'AES-256-ECB');
$aes = Encryption::aesFactory()::createAes($key, Openssl::CODING_BASE64, 'AES-256-ECB');
$str = 'test aes ecb encryption, coding with base64.';
$encrypted = $aes->encrypt($str);
printf("encrypt str: " . $encrypted);
echo PHP_EOL . '</br>';
printf("decrypt str: " . $aes->decrypt($encrypted));
echo PHP_EOL . '</br>';
echo PHP_EOL . '</br>';
/* ======== coding with HexBin ======== */
// $aes = AesFactory::createAes($key, Openssl::CODING_HEX_BIN, 'AES-256-ECB');
// $aes = Encryption::$aes::createAes($key, Openssl::CODING_HEX_BIN, 'AES-256-ECB');
$aes = Encryption::aesFactory()::createAes($key, Openssl::CODING_HEX_BIN, 'AES-256-ECB');
$str = 'test aes ecb encryption, coding with hexbin.';
$encrypted = $aes->encrypt($str);
printf("encrypt str: " . $encrypted);
echo PHP_EOL . '</br>';
printf("decrypt str: " . $aes->decrypt($encrypted));
echo PHP_EOL . '</br>';
echo PHP_EOL . '</br>';
/* ======== coding with Base64 ======== */
$aes = Encryption::aesFactory()::createAes($key, Openssl::SHA1_DIGEST | Openssl::CODING_BASE64, 'AES-256-ECB');
$str = 'test aes ecb encryption, coding with base64, key digest with sha1.';
$encrypted = $aes->encrypt($str);
printf("encrypt str: " . $encrypted);
echo PHP_EOL . '</br>';
printf("decrypt str: " . $aes->decrypt($encrypted));
echo PHP_EOL . '</br>';
echo PHP_EOL . '</br>';