【发布时间】:2016-07-28 20:57:08
【问题描述】:
我正在尝试从某个位置解密 .pgp 文件,然后将这些文件移动到另一个位置。我查看了这个article 并相应地编码。在我的代码中,我正在开发一个应用程序,它将在每 100 秒后检查到某个位置,如果有文件,那么它将解密并移动。但我得到了这个例外The process cannot access the file 'c:\file.pgp' because it is being used by another process.
这是我调用从那篇文章中复制的类的代码。
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
//Do the stuff you want to be done every hour;
string sourcePath = @"files location";
string archivePath = @"move original file after decrypting location";
string targetPath = @"decrypted file location";
string pubkeyPath = @"public key location\PGPPublicKey.txt";
string privkeyPath = @"private key location\PGPPrivateKey.txt";
string fileName = "";
string destFile = "";
if (System.IO.Directory.Exists(sourcePath))
{
string[] files = System.IO.Directory.GetFiles(sourcePath);
// Copy the files and overwrite destination files if they already exist.
foreach (string s in files)
{
PGPDecrypt test = new PGPDecrypt(s,
privkeyPath,
"password",
targetPath + "decrypted.txt",
pubkeyPath);
FileStream fs = File.Open(s, FileMode.Open);
test.decrypt(fs, targetPath + "decrypted.txt");
// Use static Path methods to extract only the file name from the path.
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(archivePath, fileName);
System.IO.File.Move(s, archivePath);
}
}
}
【问题讨论】:
标签: c# encryption bouncycastle public-key-encryption pgp