Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  101] [ 7]  / answers: 1 / hits: 23514  / 11 Years ago, fri, may 17, 2013, 12:00:00

I would like to know if it is possible to encrypt and decrypt a text, using pure JavaScript. I don't want to use a key. It may be an entry lever solution. But I simply want to encode a text my-name-1 into some text format and want to retrieve the text from it. Is this possible, without using any js libraries?


More From » encryption

 Answers
33

Without a key (or some secret for that matter), you wont get any kind of encryption.



What you mean is something like a different encoding. So maybe Base64 is something for you.



var baseString = 'my-name-1';

var encodedString = window.btoa( baseString ); // returns bXktbmFtZS0x

var decodedString = window.atob( encodedString ); // returns my-name-1


This is supported in all major browsers. IE support just in IE10+.



References:




[#78166] Thursday, May 16, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tammyb

Total Points: 278
Total Questions: 101
Total Answers: 103

Location: Botswana
Member since Sat, Jan 7, 2023
1 Year ago
tammyb questions
Sat, Aug 15, 20, 00:00, 4 Years ago
Wed, Sep 25, 19, 00:00, 5 Years ago
Sun, Jun 9, 19, 00:00, 5 Years ago
;