Tuesday, June 4, 2024
 Popular · Latest · Hot · Upcoming
32
rated 0 times [  33] [ 1]  / answers: 1 / hits: 61065  / 12 Years ago, tue, january 22, 2013, 12:00:00

I'm looking for a way to obfuscate and deobfuscate a string in JavaScript; by which I mean encryption and decryption when security is not an issue. Ideally something native to JS (like base64_encode() and base64_decode() in PHP) to turn a string into something else and back again without having to write a function.



Any suggestions welcome!


More From » encryption

 Answers
319

You can use btoa() and atob(). btoa() is like base64_encode() and atob() like base64_decode().



Here is an example:



btoa('Some text'); // U29tZSB0ZXh0
atob('U29tZSB0ZXh0'); // Some text


Keep in mind that this is not a secure way to keep secrets. Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format by translating it into a radix-64 representation.


[#80711] Sunday, January 20, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleedayanarar

Total Points: 303
Total Questions: 90
Total Answers: 102

Location: Virgin Islands (U.S.)
Member since Tue, Jul 7, 2020
4 Years ago
;