最简单的方式来模糊和混淆JavaScript中的字符串 [英] Simplest way to obfuscate and unobfuscate a string in JavaScript

查看:590
本文介绍了最简单的方式来模糊和混淆JavaScript中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在JavaScript中混淆和混淆字符串的方法;我的意思是加密和解密时,安全性不是问题。理想情况下,JS(如PHP中的 base64_encode() base64_decode())本身就是将字符串变成某种东西

I'm looking for a way to obfuscate and unobfuscate 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

唯一的问题是这些功能不是跨浏览器。对于跨浏览器编码/解码,您可以使用 http://code.google.com/p/javascriptbase64/

The only problem is that these functions are not cross-browser. For cross-browser encoding/decoding you can use http://code.google.com/p/javascriptbase64/

这篇关于最简单的方式来模糊和混淆JavaScript中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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