encryptData 解密 demo 中的 php 代码 mcrypt
```php
try {
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, ‘’, MCRYPT_MODE_CBC, ‘’);
mcrypt_generic_init($module, $this->key, $aesIV);
//解密
$decrypted = mdecrypt_generic($module, $aesCipher);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
} catch (Exception $e) {
return array(ErrorCode::$IllegalBuffer, null);
}
```
在 php7.1 运行中会报错 请官方 更新
2 回复
//php7.1+ openssl解密 public function decrypted_openssl( $appid , $sessionKey , $encryptedData , $iv ){ if ( strlen ( $appid )==0 || strlen ( $sessionKey ) != 24 || strlen ( $iv ) != 24 || strlen ( $encryptedData )==0) { return false; } $encrypted = base64_decode ( $encryptedData ); $aesiv = base64_decode ( $iv ); if ( strlen ( $aesiv )<4 || strlen ( $aesiv )>16){ return false; } $result =openssl_decrypt( $encrypted , 'aes-128-cbc' , base64_decode ( $sessionKey ), OPENSSL_RAW_DATA, $aesiv ); //string openssl_encrypt ( string $data , string $method , string $key [, int $options = 0 [, string $iv = "" [, string &$tag = NULL [, string $aad = "" [, int $tag_length = 16 ]]]]] ) //tag_length //The length of the authentication tag. Its value can be between 4 and 16 for GCM mode. if (! $result ){ return false; } $result =json_decode( $result ); if ( empty ( $result )){ return false; } if ( $result ->watermark->appid != $appid ){ return false; } return $result ; } |
拿去用吧,俺也是从php5.x升到7.1跳了这个坑,搞了一个通宵研究出来的。