base64 decode encode code in javascript with example

 Here's an example of how to encode and decode data using Base64 in JavaScript:

Encoding:

// string to be encoded let stringToEncode = "Hello, World!"; // encode the string using Base64 let encodedString = btoa(stringToEncode); console.log(encodedString); // "SGVsbG8sIFdvcmxkIQ=="


Decoding:

// string to be decoded let stringToDecode = "SGVsbG8sIFdvcmxkIQ=="; // decode the string using Base64 let decodedString = atob(stringToDecode); console.log(decodedString); // "Hello, World!"

In the above example, we use the btoa() function to encode the string, and atob() function to decode the string. Note that btoa() and atob() functions are not available in all browsers, so you may need to use a polyfill or a library like base64-js to ensure cross-browser compatibility.

Also, keep in mind that while Base64 encoding is useful for encoding data to be sent over the network, it is not a secure form of encryption and should not be used for storing sensitive data.

No comments:

Post a Comment

python code to Twilio SMS

Here's an example of a TwilioSMS class that you can use to send SMS messages using the Twilio Python helper library: import os from twil...