I'm trying to encrypt and decrypt in JavaScript using TripleDES.js. Here is my code snippet:
Encryption Method:
encrypt_string = function (plainData) {
var encrypted = CryptoJS.TripleDES.encrypt(plainData, "My Secret Key");
alert("Encrypted: " + encrypted);
}
Decryption Method:
decrypt_string = function (cipherData) {
var decrypted = CryptoJS.TripleDES.decrypt(cipherData, "My Secret Key");
alert("Decrypted: " + decrypted);
}
While passing plainData
as Gokul Nath
, to encrypt_string()
, the alert message shows:
U2FsdGVkX1/huVhh9IQhJF72gcs26f1l0+hNSsWEXsc=
While passing cipherData
as U2FsdGVkX1/huVhh9IQhJF72gcs26f1l0+hNSsWEXsc=
, to decrypt_string()
, the alert message shows:
476f6b756c204e617468
Question: How to get the original plain data while decrypting?
476f6b756c204e617468
is the hex representation of the original string:You can use something like
decrypted.toString(CryptoJS.enc.Latin1)
to get the string value, as per:which gives: