admin管理员组文章数量:1389754
I was wondering if anyone knew of a quick library or some solution which basically does this.
code({ json: 1 }) -> codedsecret
decode(codedSecret) -> { json: 1 }
Basically, I'm looking for a way to translate JSON to an encoded string that most folks won't be able to understand for security reasons.
I was wondering if anyone knew of a quick library or some solution which basically does this.
code({ json: 1 }) -> codedsecret
decode(codedSecret) -> { json: 1 }
Basically, I'm looking for a way to translate JSON to an encoded string that most folks won't be able to understand for security reasons.
Share Improve this question asked Apr 3, 2013 at 23:26 adrianadrian 2,3864 gold badges33 silver badges49 bronze badges 3- 1 Perhaps Crypto JS? (with all the usual caveats about client-side security) – Tim M. Commented Apr 3, 2013 at 23:30
- Yeah I just saw that, might work well thanks – adrian Commented Apr 3, 2013 at 23:30
- You can reverse your string :) – Ivan Kuckir Commented Apr 3, 2013 at 23:41
1 Answer
Reset to default 6If by "most folks" you mean non-sneaky developers, then base64 is probably sufficient. Modern browsers should implement btoa
and atob
(both directions), but there are libraries out there in case you need more patibility.
var secret = btoa(JSON.stringify({json: 1}));
JSON.parse(atob(secret)); // {json: 1}
This offers no cryptographic security at all and is easily cracked by developers who can recognize and even decode base64 strings visually. If you need to cover those two circumstances, then you need to look into encrypting on the server side before municating with the client and vice versa. There are OpenSSL implementations for JavaScript, but I'm not sure how much I'd trust them.
本文标签: javascriptJSON to hashed valueStack Overflow
版权声明:本文标题:javascript - JSON to hashed value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744606149a2615366.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论