简体   繁体   中英

Simple JavaScript encryption & decryption without using key

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 ?

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM