Categories
JavaScript Answers

How to decode a base64 string using CryptoJS with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *