在PHP中实现Java下使用SecureRandom SHA1PRNG算法进行AES-128-ECB(AES/ECB/PKCS5Padding)加解密:
function encrypt($data, $password)
{
$key = substr(openssl_digest(openssl_digest($password, 'sha1', true), 'sha1', true), 0, 16);
$result = openssl_encrypt($data, 'AES-128-ECB', $key);
return $result;
}
function decrypt($data, $password)
{
$key = substr(openssl_digest(openssl_digest($password, 'sha1', true), 'sha1', true), 0, 16);
return openssl_decrypt($data, 'AES-128-ECB', $key);
}
发表回复