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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
<?php
require_once dirname(__FILE__).'/../../secure/Crypt/TripleDES.php';
/** * * @author kblee * */ class BlockEncrypt{ /** * singleton instance. */ private static $instance; /** * encrypt/decrypt key */ private $keyData; /** * Create a single BlockEncrypt class. */ private function BlockEncrypt(){ $this->initailizePrivateKey(); } /** * Configure encrypt key from key file. */ private function initailizePrivateKey(){ $filePath = dirname(__FILE__).'/nicepay.key'; $fp = fopen($filePath,'r'); $this->keyData = fread($fp,24); fclose($fp); } /** * Get a BlockEncrypt instance. */ public static function getInstance(){ if(!isset(BlockEncrypt::$instance)){ BlockEncrypt::$instance = new BlockEncrypt(); } return BlockEncrypt::$instance; } /** * encrypt plainText with configured key. */ public function encrypt($plainText){ $aes = new Crypt_TripleDES(CRYPT_DES_MODE_ECB); $aes->setKey($this->keyData); return $aes->encrypt($plainText); } /** * decrypt cipherText with configured key. */ public function decrypt($cipher){ $aes = new Crypt_AES(CRYPT_AES_MODE_ECB);
$aes->setKey($this->keyData);
return $aes->decrypt($cipher); }
}
?>
|