在JavaScript中对字符串进行模糊处理和反混淆的最简单方法 [英] Simplest way to obfuscate and deobfuscate a string in JavaScript

查看:723
本文介绍了在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆