php代码,php很多东西都是提供好的,直接用函数,但是php目前所知填充模式只有ZeroPadding,于是其他语言就只能跟着它来了: - $privateKey = "1234567812345678";
- $iv = "1234567812345678";
- $data = "Test String";
- //加密
- $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $privateKey, $data, MCRYPT_MODE_CBC, $iv);
- echo($encrypted);
- echo '
'; - echo(base64_encode($encrypted));
- echo '
'; - //解密
- $encryptedData = base64_decode("2fbwW9+8vPId2/foafZq6Q==");
- $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $privateKey, $encryptedData, MCRYPT_MODE_CBC, $iv);
- echo($decrypted);
- ?>
|