C# 保护客户端json
我是Windows应用商店应用程序开发新手。我正在创建一个Windows应用商店应用程序,它需要在客户端存储一些数据。此数据以JSON格式显示,其中包含构建操作作为内容。每当用户运行应用程序时,我都会通过读取这个JSON文件来初始化一些对象。但是,这只是一个纯文本,包含不应向用户透露的数据。我可以用任何方式加密这个JSON吗。我基本上需要一种变通方法,在构建应用程序时加密json数据,在读取和初始化对象时解密此json。请建议。我假设您的代码如下所示:C# 保护客户端json,c#,json,xaml,encryption,windows-store-apps,C#,Json,Xaml,Encryption,Windows Store Apps,我是Windows应用商店应用程序开发新手。我正在创建一个Windows应用商店应用程序,它需要在客户端存储一些数据。此数据以JSON格式显示,其中包含构建操作作为内容。每当用户运行应用程序时,我都会通过读取这个JSON文件来初始化一些对象。但是,这只是一个纯文本,包含不应向用户透露的数据。我可以用任何方式加密这个JSON吗。我基本上需要一种变通方法,在构建应用程序时加密json数据,在读取和初始化对象时解密此json。请建议。我假设您的代码如下所示: string json = File.Re
string json = File.ReadAllText("/<path to json>/config.json");
// Parse the json ...
string json=File.ReadAllText(“//config.json”);
//解析json。。。
您可以使用AES加密来加密JSON文件的内容。
您需要定义一个用于加密和解密的密钥
在这里看一看:
使用加密后,您的代码将如下所示:
string json = File.ReadAllText("/<path to json>/config.json");
// Parse the json ...
当您需要读取配置时:
string encryptedJson = File.ReadAllText("/<path to json>/config.json");
string aesKey = "<your aes key>";
string plainJson = AesDecrypt(encryptedJson, aesKey);
// Parse the json ...
// Generate json ...
string plainJson;
string aesKey = "<your aes key>";
string encryptedJson = AesEncrypt(plainJson, aesKey);
File.WriteAllText("/<path to json>/config.json", encryptedJson);
string encryptedJson=File.ReadAllText(“//config.json”);
字符串aesKey=“”;
字符串plainJson=AESEcrypt(encryptedJson,aesKey);
//解析json。。。
需要保存配置时:
string encryptedJson = File.ReadAllText("/<path to json>/config.json");
string aesKey = "<your aes key>";
string plainJson = AesDecrypt(encryptedJson, aesKey);
// Parse the json ...
// Generate json ...
string plainJson;
string aesKey = "<your aes key>";
string encryptedJson = AesEncrypt(plainJson, aesKey);
File.WriteAllText("/<path to json>/config.json", encryptedJson);
//生成json。。。
字符串纯JSON;
字符串aesKey=“”;
字符串encryptedJson=AesEncrypt(纯JSON,aesKey);
File.WriteAllText(“//config.json”,encryptedJson);
请注意,可以使用反射方法从编译的程序集中提取密钥谢谢。你的方法很好,但我有不同的解决办法。我将构建操作作为嵌入式资源。看这个,这还不是秘密。JSON数据的值是多少?@PeterTorr MSFT-存储在磁盘上的文件按照OP descriped进行加密,但密钥在应用程序中,对吗?你在保护什么?1)在(底部)的粗体注释中已经提到,2)它意味着隐藏可供所有人读取的普通数据,存储在磁盘上。