使用asp.net C#加密所有类型的文件 [英] encrypt all types of files using asp.net c#
本文介绍了使用asp.net C#加密所有类型的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
文件类型:pdf,word,视频,音频
我已上传文件.我希望我的文件应采用加密格式.无法读取的格式.
types of files: pdf,word,video,audio
I have uploaded files. i want my file should be in encrypted format.unreadable format.
protected void UploadFileToSharePoint(string UploadedFilePath, string SharePointPath)
{
WebResponse response = null;
try
{
// Create a PUT Web request to upload the file.
WebRequest request = WebRequest.Create(SharePointPath);
File.Encrypt(SharePointPath);
request.Credentials = CredentialCache.DefaultCredentials;
request.Method = "PUT";
// Allocate a 1 KB buffer to transfer the file contents.
// You can adjust the buffer size as needed, depending on
// the number and size of files being uploaded.
byte[] buffer = new byte[1024];
// Write the contents of the local file to the
// request stream.
using (Stream stream = request.GetRequestStream())
using (FileStream fsWorkbook = File.Open(UploadedFilePath,
FileMode.Open, FileAccess.Read))
{
int i = fsWorkbook.Read(buffer, 0, buffer.Length);
while (i > 0)
{
stream.Write(buffer, 0, i);
i = fsWorkbook.Read(buffer, 0, buffer.Length);
}
}
// Make the PUT request.
response = request.GetResponse();
}
catch (Exception ex)
{
throw ex;
}
finally
{
response.Close();
}
}
推荐答案
.NET已经提供了加密文件的功能.您可以查看这篇MSDN文章,其中解释了如何实现该目标:
http://support.microsoft.com/kb/307010/zh-CN [ ^ ]
.NET already provides the ability to encrypt files. You could look at this MSDN article which explains how to achieve that:
http://support.microsoft.com/kb/307010/en-us[^]
这篇关于使用asp.net C#加密所有类型的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文