我在基本加密/解密方面遇到了麻烦.我一直在寻找一个有效的例子,但还没有找到一个有效的例子.
- 我将在php中进行加密,使用cryptoj解密以获得一小部分安全性
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js">
<?
$text = "this is the text here";
$key = "encryptionkey";
$msgEncrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CBC, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND));
$msgBase64 = trim(base64_encode($msgEncrypted));
echo "<h2>PHP</h2>";
echo "<p>Encrypted:</p>";
echo $msgEncrypted;
echo "<p>Base64:</p>";
echo $msgBase64;
?>
<p>AES Decrypt</p>
<script>
var key = 'encryptionkey';
var encrypted = "<?php echo $msgBase64 ?>";
//tried var base64decode = CryptoJS.enc.Base64.parse(encrypted);
var decrypted = CryptoJS.AES.decrypt(encrypted, key);
console.log( decrypted.toString(CryptoJS.enc.Utf8) );
</script>
Run Code Online (Sandbox Code Playgroud)
我错过了哪一步?