C# PGP加密导致程序在多次文件加密后崩溃

C# PGP加密导致程序在多次文件加密后崩溃,c#,encryption,console-application,bouncycastle,pgp,C#,Encryption,Console Application,Bouncycastle,Pgp,我按照中的代码构建了一个控制台应用程序,可以同时加密多个文件 使用该应用程序,我加密了大量文件(我尝试的最大值为4)。我注意到,在第二次或第三次文件加密后,程序自动关闭,没有任何错误。这发生在调试和发布环境中 我不明白为什么。有人知道吗 我在其上实现了一个助手类,其内容如下: namespace PgPSignAndEncryption.Helper { public class PgPHelperClass { private string JKSBPublic

我按照中的代码构建了一个控制台应用程序,可以同时加密多个文件

使用该应用程序,我加密了大量文件(我尝试的最大值为4)。我注意到,在第二次或第三次文件加密后,程序自动关闭,没有任何错误。这发生在调试和发布环境中

我不明白为什么。有人知道吗

我在其上实现了一个助手类,其内容如下:

namespace PgPSignAndEncryption.Helper
{
    public class PgPHelperClass
    {
        private string JKSBPublicKey = PgPSignAndEncryptionForCiti.Properties.Settings.Default.PgPPublicKeyPath;
        private string JKSBPrivateKey = PgPSignAndEncryptionForCiti.Properties.Settings.Default.PgPPrivateKeyPath;
        private string JKSBSecretKey = "MySecretKey";

        private string _encryptedFileName = string.Empty;
        private string _decryptedFileName = string.Empty;

        public string EncryptedFileName
        {
            get { return _encryptedFileName; }
            set { _encryptedFileName = value; }
        }
        public string DecryptedFileName
        {
            get { return _decryptedFileName; }
            set { _decryptedFileName = value; }
        }

        public void KeyGeneration()
        {
            #region PublicKey and Private Key Generation 

            PgPSignAndEncryption.KeyGeneration.KeysForPGPEncryptionDecryption.GenerateKey("Me", "MySecretKeys", @"C:\Keys\");
            //Console.WriteLine("Keys Generated Successfully");

            #endregion
        }

        public void Encryption()
        {
            try
            {
                #region PGP Encryption 

                PgpEncryptionKeys encryptionKeys = new PgpEncryptionKeys(this.JKSBPublicKey, this.JKSBPrivateKey, this.JKSBSecretKey);
                PgpEncrypt encrypter = new PgpEncrypt(encryptionKeys);

                var path = System.IO.Path.GetDirectoryName(this.DecryptedFileName);
                var fileName = System.IO.Path.GetFileNameWithoutExtension(this.DecryptedFileName);
                var ext = System.IO.Path.GetExtension(this.DecryptedFileName);
                this.EncryptedFileName = string.Format("{0}\\{1}{2}.gpg", path, fileName, ext);

                using (Stream outputStream = File.Create(this.EncryptedFileName))
                {
                    encrypter.EncryptAndSign(outputStream, new FileInfo(this.DecryptedFileName));
                }

                //EncryptedFileName = this.EncryptedFileName;

                #endregion
            } //<<<<<<<<<------ It crashes after this point!
            catch (Exception er)
            {
                EncryptedFileName = er.Message;
            }  
        }

        public void Decryption(out string DecryptedFileName)
        {
            try
            {
                #region PGP Decryption 

                var path = System.IO.Path.GetDirectoryName(this.EncryptedFileName);
                var fileName = System.IO.Path.GetFileNameWithoutExtension(this.EncryptedFileName);
                var ext = string.Empty;
                //try
                //{
                //    var aExt = fileName.Split('.');
                //    fileName = aExt.First();
                //    ext = aExt.Last();
                //}
                //catch (Exception)
                //{
                //    ext = System.IO.Path.GetExtension(this.EncryptedFileName);
                //}
                this.DecryptedFileName = string.Format("{0}\\{1}.out", path, fileName);

                PGPDecrypt.Decrypt(this.EncryptedFileName, this.JKSBPrivateKey, this.JKSBSecretKey, this.DecryptedFileName);

                DecryptedFileName = this.DecryptedFileName;

                #endregion
            }
            catch (Exception er)
            {
                DecryptedFileName = er.Message;
            }

        }
    }
}

将断点放入try块并单步执行。然后,您应该能够检查异常消息和类型以及堆栈跟踪。将这些信息添加到问题中。崩溃可能与I/O或硬件相关,因为您描述的通用.NET异常不会引发。文件是否已成功加密和签名?请尝试暂时禁用病毒扫描程序。我让McAfee搞乱了很多结果(包括我的安全相关软件的版本!!!)-虽然McAfee是最糟糕的病毒扫描程序,但我想其他病毒扫描程序也可能会阻止访问并触发错误。@MaartenBodewes你说得很对!我有卡巴斯基在我的,我残疾,然后尝试,然后过程运作良好,没有任何崩溃。让我再做几轮测试,以确保绝对可靠。@Fildor在日志中没有发现任何相关内容,甚至:(将断点插入try块并单步执行。然后您应该能够检查异常消息和类型以及堆栈跟踪。将这些信息添加到问题中。崩溃可能与I/O或硬件有关,因为根据您描述的一般.NET异常没有被抛出。文件是否成功加密和签名ed?请暂时禁用病毒扫描程序。我让McAfee搞乱了许多结果(包括我的安全相关软件的版本!!!)-虽然McAfee是最糟糕的病毒扫描程序,但我想其他病毒扫描程序也可能会阻止访问并触发错误。@MaartenBodewes你说得很好!我有卡巴斯基,我禁用了,然后尝试了,然后这个过程运行得很好,没有任何崩溃。让我再做几轮测试以确保绝对正确。@Fildor在日志中未找到任何相关信息,甚至:(
private static void BulkFileEncryption()
        {
            if (Directory.Exists(PickUpFolderPath))
            {
                var files = Directory.GetFiles(DropFolderPath);
                foreach (var file in files)
                {
                    //Encryption and Decryption
                    helper.DecryptedFileName = file;

                    helper.Encryption();
                    Console.WriteLine(string.Format("File Encrypted: {0}", file));
                }
            }
        }