Skip to content

Commit

Permalink
修改加解密参数
Browse files Browse the repository at this point in the history
  • Loading branch information
SiZhe committed Sep 20, 2018
1 parent 49c90d8 commit 4c777af
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/crypto/pkcs7Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function encrypt($text, $corpid)
$iv = substr($this->key, 0, 16);
$pkc_encoder = new PKCS7Encoder;
$text = $pkc_encoder->encode($text);
$encrypted = openssl_encrypt($text,'AES-128-CBC', $this->key, 0, $iv);
$encrypted = openssl_encrypt($text, 'AES-256-CBC', substr($this->key, 0, 32), OPENSSL_ZERO_PADDING, $iv);
return array(ErrorCode::$OK, $encrypted);
} catch (\Exception $e) {
print $e;
Expand All @@ -64,16 +64,20 @@ public function decrypt($encrypted, $corpid)

try {
$iv = substr($this->key, 0, 16);
$decrypted = openssl_decrypt($encrypted, 'AES-128-CBC', $this->key, 0, $iv);
$decrypted = openssl_decrypt($encrypted, 'AES-256-CBC', substr($this->key, 0, 32), OPENSSL_ZERO_PADDING, $iv);

} catch (\Exception $e) {
return array(ErrorCode::$DecryptAESError, null);
}

try {

$pkc_encoder = new PKCS7Encoder;
$result = $pkc_encoder->decode($decrypted);
dd($result);
if (strlen($result) < 16)
return "";

$content = substr($result, 16, strlen($result));
$len_list = unpack("N", substr($content, 0, 4));
$xml_len = $len_list[1];
Expand Down

0 comments on commit 4c777af

Please sign in to comment.