Simplest way to obfuscate and deobfuscate a string in JavaScript

前端 未结 3 1515
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 17:04

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

3条回答
  •  醉梦人生
    2020-12-04 17:12

    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.

提交回复
热议问题