java实现AES算法(已有运行的PHP版本)
最近有一个需求,需要将php写的加密算法用java实现,php的代码已经有了,但是用java改写,尝试了好多久也没有成功。有知道的同学,希望不吝赐教,谢谢。
<?php
function simple_encrypt($text)
{
$key = "anything";
$iv = 'MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=';
$key = hash('sha256', $key, true);
$iv = base64_decode($vi);
return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CBC, $iv)));
}
function simple_decrypt($text)
{
$key = "anything";
$iv = 'MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=';
$key = hash('sha256', $key, true);
$iv = base64_decode($vi);
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($text), MCRYPT_MODE_CBC, $iv));
}
$en = simple_encrypt($str);
$de = simple_decrypt($en);
var_dump($en, $de);
执行结果:
string(44) "OgmKJ5gu4rRYB47pVV5N1GyTW5+aKNjQnx2TFYjNdUI="
string(19) "1234567890987654321"
你们这群年轻人
10 years, 6 months ago