简体   繁体   English

在C#中保护和加密.mdb文件

[英]securing and encrypting .mdb file in c#

I want to make my MS Access file (.mdb) unreadable/readable based on a key, using C#. 我想使用C#基于密钥使我的MS Access文件(.mdb)不可读/可读。 I want to do this without using any third party tools. 我想这样做而不使用任何第三方工具。 How can I do this? 我怎样才能做到这一点?

This should be all you need: 这应该是您所需要的:

http://msdn.microsoft.com/en-us/library/0dh224hh.aspx http://msdn.microsoft.com/zh-CN/library/0dh224hh.aspx

This uses DESEncryption, and you should setup the IV (initialisation vector) to anything you want, as long as it's always the same, and the key (your password) can only be 8 bytes long. 这使用DESEncryption,您应该将IV(初始化向量)设置为所需的任何东西,只要它始终是相同的,并且密钥(您的密码)只能是8个字节长。

To convert a string to bytes, you can use 要将字符串转换为字节,可以使用

System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
byte[] bkey = ue.GetBytes(key);

I'll leave it up to you to make that 8 bytes long. 我将把这8个字节留给您。

You may also want to store somewhere (eg another file) whether or not the mdb file is currently encrypted, because you don't want to end up encrypting it multiple times... in which case it could be quite hard to get it back. 您可能还想将mdb文件当前是否加密,存储在某个地方(例如,另一个文件),因为您不想结束多次对其进行加密...在这种情况下,很难将其恢复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM