Rumah >pembangunan bahagian belakang >tutorial php >java实现AES算法(已有运行的PHP版本)
最近有一个需求,需要将php写的加密算法用java实现,php的代码已经有了,但是用java改写,尝试了好多久也没有成功。有知道的同学,希望不吝赐教,谢谢。
<code><?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" </code></code>
最近有一个需求,需要将php写的加密算法用java实现,php的代码已经有了,但是用java改写,尝试了好多久也没有成功。有知道的同学,希望不吝赐教,谢谢。
<code><?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" </code></code>
为何不百度
http://www.cnblogs.com/freeliver54/archive/2011/10/08/2202136.html
使用mcrypt_encrypt方法出现500的错误