数据通讯均采用AES/CBC/PKCS5Padding模式加密,并于加密之前的字符串最后追加{0000}
加密iv和密钥均为:1102130405061708
demo:
php:
~~~
class PayModels{
var $iv="1102130405061708";
//加密
private function encrypt($encryptStr) {
$encryptStr.="{0000}";
$localIV = $this->iv;
$encryptKey = $this->iv;
//Open module
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, $localIV);
//print "module = $module <br/>" ;
mcrypt_generic_init($module, $encryptKey, $localIV);
//Padding
$block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$pad = $block - (strlen($encryptStr) % $block); //Compute how many characters need to pad
$encryptStr .= str_repeat(chr($pad), $pad); // After pad, the str length must be equal to block or its integer multiples
//encrypt
$encrypted = mcrypt_generic($module, $encryptStr);
//Close
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
return base64_encode($encrypted);
}
//解密
private function decrypt($str){
$localIV = $this->iv;
$encryptKey = $this->iv;
//Open module
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, $localIV);
//print "module = $module <br/>" ;
mcrypt_generic_init($module, $encryptKey, $localIV);
$encryptedData = base64_decode($str);
$encryptedData = mdecrypt_generic($module, $encryptedData);
$res= explode("{0000}", $encryptedData);
$encryptedData=$res[0];
return $encryptedData;
}
}
~~~