Achraf.Davinci Achraf.Davinci - 4 months ago 18
Javascript Question

Can't print CryptoJS-encrypted ciphertext to page

I can't access the

variable with jQuery but in
it works!!!

<script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="js/aes.js"></script>
$( document ).ready(function() {
var textToEncrypt = "textToEncrypt";
var secretPhrase = "secretPhrase";
var encryptedData = CryptoJS.AES.encrypt(textToEncrypt, secretPhrase);

<div id="data"></div>


encryptedData is a CipherParams object containing various properties such as ciphertext, salt and iv. jQuery's text function takes this object and tries to assign it directly to the element. alert on the other hand first stringifies it. You probably want: