1,废话不多说直接上代码,先写一个类
class Crypt {
/**
* [$cipher 加密模式]
* @var [type]
*/
private $cipher = MCRYPT_RIJNDAEL_128;
private $mode = MCRYPT_MODE_CBC;
/**
* [$key 密匙]
* @var string
*/
private $secret_key = 'dc1e8b9ace2d60d3992ecb5e30825253';
function setCipher($cipher=''){
$cipher && $this->cipher = $cipher;
}
function setMode($mode=''){
$mode && $this->mode = $mode;
}
function setSecretKey($secret_key=''){
$secret_key && $this->secret_key = $secret_key;
}
//加密
function encrypt($str,$iv)
{
$size = mcrypt_get_block_size ( MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC );
$str = $this->pkcs5Pad ( $str, $size );
//$data=mcrypt_cbc(MCRYPT_RIJNDAEL_128, $this->secret_key, $str, MCRYPT_ENCRYPT, $this->iv);
//$data=mcrypt_encrypt(MCRYPT_DES, $this->secret_key, $str, MC

本文介绍如何实现在PHP和Java之间进行AES加密解密的互通。首先展示了一个包含加密解密功能的PHP类,接着演示了如何传递参数并调用加密方法。此外,还提供了一个简洁的备用加密方法。
最低0.47元/天 解锁文章
7832





