我需要在一个asp net mvc应用程序中创建一个加密文件容器。
我找到了一个可以完成这个任务的程序。
http://www.michaelcodes.net/post/TrueCrypt-6a-System-Encryption-Benchmarks.aspx
但它应该与.NET集成。
有没有使用.NET库完成这个任务的方法?我还没有找到如何做到。
特性:
- 系统需要能够从内部添加和删除文件,并在请求时读取内容。但所有操作都需要从系统内部完成。
- C#实现
我需要在一个asp net mvc应用程序中创建一个加密文件容器。
我找到了一个可以完成这个任务的程序。
http://www.michaelcodes.net/post/TrueCrypt-6a-System-Encryption-Benchmarks.aspx
但它应该与.NET集成。
有没有使用.NET库完成这个任务的方法?我还没有找到如何做到。
特性:
[Serializable]
public class FileEntry
{
public string FileName {get;set;}
public string FileRelativePath {get;set;}
public byte[] FileContents {get;set;}
}
List<FileEntry> files = new List<FileEntry> ();
for .......
{
files.Add(new FileEntry()
{
FileName = .....,
FileRelativePath = .....,
FileContents = File.ReadAllBytes(......),
};
}
byte[] filesBytes;
BinaryFormatter ser = new BinaryFormatter();
using(MemoryStream ms = new MemoryStream())
{
ser.Serialize(ms, files);
filesBytes = ms.ToArray();
}
filesBytes = Encrypt(filesBytes , ......);
File.WriteAllBytes(".........\.....encr",filesBytes);
byte[] encryptedData = File.ReadAllBytes(".......\.....encr");
byte[] clearContent = Decrypt(encryptedData, ......);
BinaryFormatter ser = new BinaryFormatter();
using(MemoryStream ms = new MemoryStream(clearContent))
{
List<FileEntry> files = ser.Deserialize(ms) as List<FileEntry>;
}
foreach(var file in files)
{
File.WriteAllBytes(string.Format("........{0}...{1}",file.FileRelativePath , file.FileName), file.FileContents)
}
这是一个关于二进制格式化程序的示例:
我已经将答案发布到我的博客上了 :)
如果您想使用TrueCrypt,您可以在系统启动时自动挂载到驱动器上,然后在映射的驱动器上使用常规文件操作。
如果您不想使用公共访问权限(即外部应用程序访问),那么您确实需要更深入的API访问。
我不建议您从头开始自己编写C#实现。要获得TrueCrypt中精细的安全级别,您需要技能和时间 - 这两者都已经投入到TC中。如果您不同时使用这两个因素,您很容易面临重大的安全风险。
您可以通过导入dll来简单地使用auto-interop(虽然我不能确定)。我相信TC是开源的,如果是这样,您可以外包一个C/C++编码人员来编写一个.Net包装器 - 一个不需要挂载卷,但允许内部应用程序仅基于文件的访问。