Achraf.Davinci Achraf.Davinci - 1 year ago 66
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>

Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download