在 JavaScript 中混淆和反混淆字符串的最简单方法 [英] Simplest way to obfuscate and deobfuscate a string in JavaScript
问题描述
我正在寻找一种在 JavaScript 中混淆和反混淆字符串的方法;我的意思是当安全不是问题时加密和解密.理想情况下,JS 原生的东西(如 PHP 中的 base64_encode()
和 base64_decode()
)可以将字符串转换为其他内容并再次返回",而无需编写函数.
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.
欢迎提出任何建议!
推荐答案
您可以使用 btoa() 和 atob().btoa()
就像 base64_encode()
和 atob()
就像 base64_decode()
.
You can use btoa() and atob(). btoa()
is like base64_encode()
and atob()
like base64_decode()
.
这是一个例子:
btoa('Some text'); // U29tZSB0ZXh0
atob('U29tZSB0ZXh0'); // Some text
请记住,这不是保密的安全方式.Base64 是一种二进制到文本的编码方案,它通过将二进制数据转换为基数 64 表示来表示 ASCII 字符串格式的二进制数据.
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.
这篇关于在 JavaScript 中混淆和反混淆字符串的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!