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
|
<?php
require_once dirname(__FILE__).'/../../secure/Crypt/AES.php';
class WebParamsCrypto { private $merchantKey; private $aes; /** * * @param unknown_type $merchantKey */ public function WebParamsCrypto($merchantKey){ $this->merchantKey = $merchantKey; $this->aes = new Crypt_AES(CRYPT_AES_MODE_ECB); $this->aes->setKey($this->initialPrivateKey()); } private function initialPrivateKey(){ $needKey = substr($this->merchantKey,0,32); $hexBytes = str_split($needKey); $length = sizeof($hexBytes) / 2; $rawBytes = array(); for($i = 0 ; $i < $length ;$i++){ $high = base_convert((string)$hexBytes[$i*2],16,10); $low = base_convert((string)$hexBytes[$i*2+1],16,10); if($high == 0){ $high = ord($hexBytes[$i*2]) % 16; } if($low == 0){ $low = ord($hexBytes[$i*2+1]) % 16; } $value = ( ($high << 4) | $low ); if($value > 127) { $value-=256; } $rawBytes[$i] = chr($value); } // for end return implode($rawBytes); } /** * * @param unknown_type $request * @param unknown_type $decryptTargets */ public function decrypt($encryptText){ return $this->aes->decrypt(base64_decode($encryptText)); } } ?>
|