我可以加密我的 JSON 数据吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14570831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 18:43:20  来源:igfitidea点击:

Can I encrypt my JSON data?

jsonencryptionpermissionsobfuscation

提问by Cris

I'm developing a JQuery web app that will be executed locally from a DVD. The app will read all the contents of a JSON file.

我正在开发一个将从 DVD 本地执行的 JQuery Web 应用程序。该应用程序将读取 JSON 文件的所有内容。

Is there a good way to encrypt or obfuscate the JSON content so that only the app can read it?

有没有好的方法来加密或混淆 JSON 内容,以便只有应用程序可以读取它?

回答by Austin Harris

If all you want is to prevent them from copying and pasting into something else, you could store it in BSON instead of JSON. http://bsonspec.org/#/specification

如果您只想防止它们复制并粘贴到其他内容中,则可以将其存储在 BSON 而不是 JSON 中。http://bsonspec.org/#/specification

Now that only OBFUSCATES it, and will not prevent a knowledgeable person from using it if they want to.

现在,只会混淆它,并且不会阻止知识渊博的人(如果他们愿意)使用它。

You could also encrypt it, but you still have a similar issue as you would be storing the decrypt key inside the javascript that loads the encrypted Json.

您也可以对其进行加密,但您仍然有类似的问题,因为您将解密密钥存储在加载加密 Json 的 javascript 中。

Anyone that really wants your data is going to be able to get it. Most browser have javascript debuggers that will let you extract, or view the data at runtime.

任何真正想要您的数据的人都将能够获得它。大多数浏览器都有 javascript 调试器,可以让您在运行时提取或查看数据。

So it mostly comes down to how much effort you want to put into making your data difficult to get at. A significantly motivated person with get at your data no matter what you do.

因此,这主要取决于您想付出多少努力来使您的数据难以获取。一个非常有动力的人,无论你做什么,都能获取你的数据。

回答by thaJeztah

If you're only able to use JavaScript (no script-engine, like php), this library may be useful: http://code.google.com/p/crypto-js/

如果你只能使用 JavaScript(没有脚本引擎,比如 php),这个库可能很有用:http: //code.google.com/p/crypto-js/

回答by b3wii

How about this: https://github.com/HazAT/jCryption? It uses RSA for the key exchange and AES for the encryption.

这个怎么样:https: //github.com/HazAT/jCryption?它使用 RSA 进行密钥交换,使用 AES 进行加密。

回答by Damian

I'm not sure which languages are supported by your platform but look at Silenciolibrary which you can use to remove or hash nodes from JSON file. You can decide which nodes should be transformed (you may want to obfuscate only some such as password) and what change should be applied (clear the content, hash or custom)

我不确定您的平台支持哪些语言,但请查看Silencio库,您可以使用它从 JSON 文件中删除或散列节点。您可以决定应该转换哪些节点(您可能只想混淆一些,例如密码)以及应该应用哪些更改(清除内容、哈希或自定义)