Sometimes, we want to decode a base64 string using CryptoJS with JavaScript.
In this article, we’ll look at how to decode a base64 string using CryptoJS with JavaScript.
How to decode a base64 string using CryptoJS with JavaScript?
To decode a base64 string using CryptoJS with JavaScript, we can use the CryptoJS.enc.Base64.parse
method.
For instance, we write:
const base64 = 'SGVsbG8gd29ybGQ=';
const words = CryptoJS.enc.Base64.parse(base64);
const textString = CryptoJS.enc.Utf8.stringify(words);
console.log(textString)
We call CryptoJS.enc.Base64.parse
with the base64
string to parse the base64 string.
Then we call CryptoJS.enc.Utf8.stringify
to convert the decrypted words
into a string.
Therefore, textString
is 'Hello world'
.
Conclusion
To decode a base64 string using CryptoJS with JavaScript, we can use the CryptoJS.enc.Base64.parse
method.