使用 ProtoBuf 时最好的加密方法是什么?

发布于 2024-07-21 04:25:56 字数 237 浏览 5 评论 0原文

我已将移动设备上的数据库从 VistaDB 迁移出去,因为它太慢了。 我现在使用 ProtoBuf 在存储卡上创建一系列平面文件,唯一的问题是显然没有加密。

哪种加密方法最适合 ProtoBuf? 我基本上将数据实体的集合序列化到文件,然后从文件反序列化回我的集合。 我认为加密的最佳位置是在读/写的 FileStream 中。

数据将包含 NI 编号、姓名和地址,因此必须是安全的。 有人有什么想法吗?

I've migrated my database on my mobile device away from VistaDB because it's just too slow. I'm now using ProtoBuf instead to create a series of flat files on a Storage Card, the only issue is there's obviously no encryption.

Which encryption method works best with ProtoBuf? I'm basically serializing a collection of data entities to a file, then deserializing from the File back into my collections. I figure the best place to put the encryption would be in the FileStream on the read/write.

The data will contain NI numbers, names and addresses, so this has to be secure. Any idea anyone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海未深 2024-07-28 04:25:56

我认为你走在正确的道路上。 您应该能够执行以下操作:

ICryptoTransform encryptor = ...
Stream encStream = new CryptoStream(outputFileStream, encryptor, CryptoStreamMode.Write);
Serializer.Serialize(encStream, obj);
encStream.FlushFinalBlock()
encStream.Close();

ICryptoTransform decryptor = ...
Stream decStream = new CryptoStream(inputputFileStream, decryptor, CryptoStreamMode.Read);
Serializer.Deserialize<Type>(decStream);
decStream.FlushFinalBlock()
decStream.Close();

有关 .NET 加密框架的基础知识(包括如何获取 ICryptoTransform 对象,请参阅其他问题,例如 在 .NET 中加密短字符串的最佳方法是什么?

I think you're on the right track. You should just be able to do something like:

ICryptoTransform encryptor = ...
Stream encStream = new CryptoStream(outputFileStream, encryptor, CryptoStreamMode.Write);
Serializer.Serialize(encStream, obj);
encStream.FlushFinalBlock()
encStream.Close();

ICryptoTransform decryptor = ...
Stream decStream = new CryptoStream(inputputFileStream, decryptor, CryptoStreamMode.Read);
Serializer.Deserialize<Type>(decStream);
decStream.FlushFinalBlock()
decStream.Close();

For the basics of .NET's encryption framework (including how to get the ICryptoTransform objects, see other questions like What’s the best way to encrypt short strings in .NET?.

他不在意 2024-07-28 04:25:56

另一种选择是通过安装系统范围的 文件系统过滤器。 这里的优点是:

  1. 您的应用程序代码与加密无关,并且加密将在本机代码中完成。
  2. 由于加密是在本机代码中完成的,因此速度会更快。
  3. 由于加密不在托管代码内部,因此进行逆向工程并找出密钥、盐等要困难得多。

当然,缺点是(对于那些不这样做的人来说)无论如何不要写 C)的问题是你不能用 C# 来写它。

Another option is to actually encrypt the entire folder where the data is stored by installing a system-wide file system filter. The advantages here are that:

  1. Your app code is agnostic to the encryption and the encryption will be done in native code.
  2. Since the encryption is done in native code, it's going to be faster
  3. Since the encryption is not inside managed code, it's a lot harder to reverse engineer and figure out your keys, salts, etc.

Of course the disadvantage (for those who don't write C anyway) is that you can't write it in C#.

夜夜流光相皎洁 2024-07-28 04:25:56

如果您担心密钥机密性。 让它基于密码,并对手动输入的密码进行多次散列以生成密钥。

If you are concerned about key confidentiality. Have it be password based, And hash the manually entered password multiple times to generate a key.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文