开发者

How to simply encode and decode a string variable

I need to simply encode a string variable (my api key) so that is not easily readable by human eyes, I need it to easily decode back to exactly the same initial string. Wha开发者_高级运维t is the standard practical and fast (less computing on the user side) way to do this?

Many thanks in advance!


If it doesn't have to be super-secure, Base64 encoding is always handy:

http://www.webtoolkit.info/javascript-base64.html


Everything you can do to obfuscate information on the client implies that you include the code for de-obfuscation right next to it.

So… apart from adding one extra step for your program (and the hypothetical attacker), you gain nothing. Well, not much anyway.

If your API key is secret, keep it on the server and let the server do the work through HTTP requests.


You could try a Javascript Obfuscator to either encode your whole script or parts. Not an absolute solution but a start to protecting your code.


you could use a 3rd party base64 encoder library: http://ostermiller.org/utils/Base64.html


Is this secret information or not?

If it is secret, you need a real encryption library and some deep thinking too make sure your secret is kept secret. I would seriously consider never sending any secret to the browser.

If this isn't secret and you just need need to send this over the URL without it getting borked then escape()/unescape() are what you are looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜