我试图访问 DestinationFileName 但它给了我一个例外,即拒绝访问路径。知道我通常在 Path 变量中传递的数据是 C:\Users\SkyDrive\SSD\SSDAssignment\SSDAssignment\MvcApplication1\Gallery\abc.jpg 并且 DestinationFileName 中的路径是 C:\Users\SkyDrive\SSD\SSDAssignment\ SSDAssignment\MvcApplication1\Gallery
FileStream InFile = new FileStream(Path, FileMode.Open);
FileStream OutputStream = new FileStream(DestinationFileName, FileMode.Create, FileAccess.ReadWrite);
任何人都知道为什么我有这个例外。
他是整个方法,这样会更清楚
public bool HybridEncription(string Path, string DestinationFileName, string PublicKey)
{
FileStream InFile = new FileStream(Path, FileMode.Open);
FileStream OutputStream = new FileStream(DestinationFileName, FileMode.Create, FileAccess.ReadWrite);
RijndaelManaged Rm = null;
byte[] ToEncBytes = null;
try
{
ToEncBytes = new byte[InFile.Length];
InFile.Read(ToEncBytes, 0, (int)InFile.Length);
//Ask to use Keys of digital signing
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(PublicKey);
Rm = new RijndaelManaged();
byte[] EncryptedKey = rsa.Encrypt(Rm.Key, false);
byte[] EncryptedIV = rsa.Encrypt(Rm.IV, false);
OutputStream.Write(EncryptedKey, 0, EncryptedKey.Length);
OutputStream.Write(EncryptedIV, 0, EncryptedIV.Length);
ICryptoTransform Transform = Rm.CreateEncryptor();
CryptoStream CStream = new CryptoStream(OutputStream, Transform, CryptoStreamMode.Write);
CStream.Write(ToEncBytes, 0, ToEncBytes.Length);
CStream.FlushFinalBlock();
OutputStream.Flush();
CStream.Close();
InFile.Close();
OutputStream.Close();
System.IO.File.Delete(Path);
return true;
}