예제 #1
0
        public void DecryptFile_DecryptSignedAndEncryptedFileWithMultipleKeys(KeyType keyType)
        {
            // Arrange
            Arrange(keyType);
            PGP           pgp  = new PGP();
            List <string> keys = new List <string>()
            {
                publicKeyFilePath1,
                publicKeyFilePath2
            };

            // Act
            pgp.EncryptFileAndSign(contentFilePath, encryptedContentFilePath, keys, privateKeyFilePath1, password1);
            pgp.DecryptFile(encryptedContentFilePath, decryptedContentFilePath1, privateKeyFilePath1, password1);
            pgp.DecryptFile(encryptedContentFilePath, decryptedContentFilePath2, privateKeyFilePath2, password2);
            string decryptedContent1 = File.ReadAllText(decryptedContentFilePath1);
            string decryptedContent2 = File.ReadAllText(decryptedContentFilePath2);

            // Assert
            Assert.True(File.Exists(encryptedContentFilePath));
            Assert.True(File.Exists(decryptedContentFilePath1));
            Assert.True(File.Exists(decryptedContentFilePath2));
            Assert.Equal(content, decryptedContent1.Trim());
            Assert.Equal(content, decryptedContent2.Trim());

            // Teardown
            Teardown();
        }
예제 #2
0
        public void DecryptFile_DecryptSignedAndEncryptedFileWithMultipleKeys(KeyType keyType)
        {
            // Arrange
            TestFactory testFactory  = new TestFactory();
            TestFactory testFactory2 = new TestFactory();

            testFactory.Arrange(keyType, FileType.Known);
            testFactory2.Arrange(KeyType.Generated, FileType.Known);

            PGP           pgp  = new PGP();
            List <string> keys = new List <string>()
            {
                testFactory.PublicKeyFilePath,
                testFactory2.PublicKeyFilePath
            };

            // Act
            pgp.EncryptFileAndSign(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, keys, testFactory.PrivateKeyFilePath, testFactory.Password);
            pgp.DecryptFile(testFactory.EncryptedContentFilePath, testFactory.DecryptedContentFilePath, testFactory.PrivateKeyFilePath, testFactory.Password);
            pgp.DecryptFile(testFactory.EncryptedContentFilePath, testFactory2.DecryptedContentFilePath, testFactory2.PrivateKeyFilePath, testFactory2.Password);
            string decryptedContent1 = File.ReadAllText(testFactory.DecryptedContentFilePath);
            string decryptedContent2 = File.ReadAllText(testFactory2.DecryptedContentFilePath);

            // Assert
            Assert.True(File.Exists(testFactory.EncryptedContentFilePath));
            Assert.True(File.Exists(testFactory.DecryptedContentFilePath));
            Assert.True(File.Exists(testFactory2.DecryptedContentFilePath));
            Assert.Equal(testFactory.Content, decryptedContent1.Trim());
            Assert.Equal(testFactory.Content, decryptedContent2.Trim());

            // Teardown
            testFactory.Teardown();
        }
예제 #3
0
파일: Program.cs 프로젝트: swalde/PgpCore
        static void Main(string[] args)
        {
            using (PGP pgp = new PGP())
            {
                // Generate keys
                pgp.GenerateKey(@"C:\TEMP\keys\public.asc", @"C:\TEMP\keys\private.asc", "*****@*****.**", "password");
                // Encrypt file
                pgp.EncryptFile(@"C:\TEMP\keys\content.txt", @"C:\TEMP\keys\content__encrypted.pgp", @"C:\TEMP\keys\public.asc", true, true);
                // Encrypt and sign file
                pgp.EncryptFileAndSign(@"C:\TEMP\keys\content.txt", @"C:\TEMP\keys\content__encrypted_signed.pgp", @"C:\TEMP\keys\public.asc", @"C:\TEMP\keys\private.asc", "password", true, true);
                // Decrypt file
                pgp.DecryptFile(@"C:\TEMP\keys\content__encrypted.pgp", @"C:\TEMP\keys\content__decrypted.txt", @"C:\TEMP\keys\private.asc", "password");
                // Decrypt signed file
                pgp.DecryptFile(@"C:\TEMP\keys\content__encrypted_signed.pgp", @"C:\TEMP\keys\content__decrypted_signed.txt", @"C:\TEMP\keys\private.asc", "password");

                // Encrypt stream
                using (FileStream inputFileStream = new FileStream(@"C:\TEMP\keys\content.txt", FileMode.Open))
                    using (Stream outputFileStream = File.Create(@"C:\TEMP\keys\content__encrypted2.pgp"))
                        using (Stream publicKeyStream = new FileStream(@"C:\TEMP\keys\public.asc", FileMode.Open))
                            pgp.EncryptStream(inputFileStream, outputFileStream, publicKeyStream, true, true);

                // Decrypt stream
                using (FileStream inputFileStream = new FileStream(@"C:\TEMP\keys\content__encrypted2.pgp", FileMode.Open))
                    using (Stream outputFileStream = File.Create(@"C:\TEMP\keys\content__decrypted2.txt"))
                        using (Stream privateKeyStream = new FileStream(@"C:\TEMP\keys\private.asc", FileMode.Open))
                            pgp.DecryptStream(inputFileStream, outputFileStream, privateKeyStream, "password");
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            var publicKey  = new EncryptionKeys(File.ReadAllText(Path.Combine(ROOT_KEYS, PUBLIC_KEY)));
            var privateKey = new EncryptionKeys(File.ReadAllText(Path.Combine(ROOT_KEYS, PRIVATE_KEY)), "Password1!");

            using (var publicPgp = new PGP(publicKey))
                using (var privatePgp = new PGP(privateKey))
                {
                    privatePgp.ClearSignFile(
                        Path.Combine(ROOT, UNENCRYPTED_FILE),
                        Path.Combine(ROOT, SIGNED_FILE));

                    publicPgp.EncryptFile(
                        Path.Combine(ROOT, SIGNED_FILE),
                        Path.Combine(ROOT, ENCRYPTED_FILE));

                    // Likely would want to use EncryptFileAndSign instead of two passes

                    privatePgp.DecryptFile(
                        Path.Combine(ROOT, ENCRYPTED_FILE),
                        Path.Combine(ROOT, DECRYPTED_FILE));

                    Console.WriteLine("It was me who signed the file: {0}", publicPgp.VerifyClearFile(Path.Combine(ROOT, DECRYPTED_FILE)));
                }

            using (var pgp = new PGP(new EncryptionKeys(File.ReadAllText(Path.Combine(ROOT_KEYS, RANDOM_PUBLIC_KEY)))))
            {
                Console.WriteLine("It was me who signed the file: {0}", pgp.VerifyClearFile(Path.Combine(ROOT, DECRYPTED_FILE)));
            }
        }
예제 #5
0
        static void Main()
        {
            using (PGP pgp = new PGP())
            {
                Console.WriteLine($"Welcome to PGPEncryptConsoleApp!");

                string tempPath                 = Path.Combine(Path.GetTempPath(), "pgpcore");
                string publicKeyFilePath        = Path.Combine(tempPath, "public.asc");
                string publicKeyBase64FilePath  = Path.Combine(tempPath, "public_base64.asc");
                string privateKeyFilePath       = Path.Combine(tempPath, "private.asc");
                string privateKeyBase64FilePath = Path.Combine(tempPath, "private_base64.asc");
                string contentFilePath          = Path.Combine(tempPath, "content.txt");
                string encryptedFilePath        = Path.Combine(tempPath, "content_encrypted.pgp");
                string decryptedFilePath        = Path.Combine(tempPath, "content_decrypted.txt");
                string username                 = null;
                int    strength                 = 4096;
                int    certainty                = 8;

                //Create temp direcory and test file
                Directory.CreateDirectory(tempPath);
                Console.WriteLine($"Created temp directory: {tempPath}");
                File.WriteAllText(contentFilePath, "Hello World PGPCore!");
                Console.WriteLine($"Created test file: {contentFilePath}");

                // Create a password
                Console.WriteLine($"Enter a password or press enter to not use a password");
                string password = ReadLine.ReadPassword();

                // Generate keys
                Spinner.Start("Generating keys...", () =>
                {
                    pgp.GenerateKey(publicKeyFilePath, privateKeyFilePath, username, password, strength, certainty);
                });
                string publicKey = File.ReadAllText(publicKeyFilePath);
                File.WriteAllText(publicKeyBase64FilePath, Convert.ToBase64String(Encoding.UTF8.GetBytes(publicKey)));
                Console.WriteLine($"Created public key: {publicKeyFilePath}");
                Console.WriteLine($"Converted public key to base64: {publicKeyBase64FilePath}");

                Console.WriteLine($"Created private key: {privateKeyFilePath}");
                string privateKey = File.ReadAllText(privateKeyFilePath);
                File.WriteAllText(privateKeyBase64FilePath, Convert.ToBase64String(Encoding.UTF8.GetBytes(privateKey)));
                Console.WriteLine($"Created private key: {privateKeyFilePath}");
                Console.WriteLine($"Converted private key to base64: {privateKeyBase64FilePath}");

                // Encrypt file
                pgp.EncryptFile(contentFilePath, encryptedFilePath, publicKeyFilePath, true, true);
                Console.WriteLine($"Encrypted test file: {encryptedFilePath}");

                // Decrypt file
                pgp.DecryptFile(encryptedFilePath, decryptedFilePath, privateKeyFilePath, password);
                Console.WriteLine($"Decrypted test file: {decryptedFilePath}");

                Console.WriteLine("Press any key to exit");
                Console.ReadLine();
            }
        }
예제 #6
0
        public void PGPDecryptTest()
        {
            PGP pgp   = new PGP();
            var input = File.OpenRead(@"c:\veneka\pgp\B0021002_484_178.OUT.gpg");
            var key   = File.ReadAllText(@"c:\veneka\pgp\PrivateKey.txt");

            var file = pgp.DecryptFile(input, key, "v3n3ka!");

            using (var fileStream = File.Create(@"c:\veneka\pgp\decrypted"))
            {
                //file.Seek(0, SeekOrigin.Begin);
                file.CopyTo(fileStream);
            }
        }
예제 #7
0
        static void Main(string[] args)
        {
            var txt      = @"C:\MyFile\pgp\data.txt";
            var pgpf     = @"C:\MyFile\pgp\20190927.pgp";
            var key      = @"C:\MyFile\pgp\FilesKey\secret-key.asc";
            var pubkey   = @"C:\MyFile\pgp\FilesKey\GLNgpgPub";
            var password = "******";

            //using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt())
            //{
            //    pgp.DecryptFileAndVerify(pgpf,txt, pubkey, key,password);
            //}

            using (var pgp2 = new PGP())
            {
                pgp2.DecryptFile(pgpf, txt, key, password);
                Console.WriteLine("Hello World!");
            }
        }
예제 #8
0
        public void DecryptFile_DecryptSignedAndEncryptedFile(KeyType keyType)
        {
            // Arrange
            Arrange(keyType);
            PGP pgp = new PGP();

            // Act
            pgp.EncryptFileAndSign(contentFilePath, encryptedContentFilePath, publicKeyFilePath1, privateKeyFilePath1, password1);
            pgp.DecryptFile(encryptedContentFilePath, decryptedContentFilePath1, privateKeyFilePath1, password1);
            string decryptedContent = File.ReadAllText(decryptedContentFilePath1);

            // Assert
            Assert.True(File.Exists(encryptedContentFilePath));
            Assert.True(File.Exists(decryptedContentFilePath1));
            Assert.Equal(content, decryptedContent.Trim());

            // Teardown
            Teardown();
        }
예제 #9
0
        public static string DecryptPGP(string filename, string privateFileName, string passphrase)
        {
            try
            {
                string name = new FileInfo(filename).Name;
                name = name.Substring(0, name.LastIndexOf('.'));

                string path = $@"{GetLocalPath()}\{name}.txt";
                using (PGP pgp = new PGP())
                {
                    pgp.DecryptFile(filename, path, privateFileName, passphrase);
                }
                return(path);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return("ERROR");
            }
        }
예제 #10
0
        public void DecryptFile_DecryptSignedAndEncryptedFile(KeyType keyType)
        {
            // Arrange
            TestFactory testFactory = new TestFactory();

            testFactory.Arrange(keyType, FileType.Known);
            PGP pgp = new PGP();

            // Act
            pgp.EncryptFileAndSign(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath, testFactory.PrivateKeyFilePath, testFactory.Password, armor: false);
            pgp.DecryptFile(testFactory.EncryptedContentFilePath, testFactory.DecryptedContentFilePath, testFactory.PrivateKeyFilePath, testFactory.Password);
            string decryptedContent = File.ReadAllText(testFactory.DecryptedContentFilePath);

            // Assert
            Assert.True(File.Exists(testFactory.EncryptedContentFilePath));
            Assert.True(File.Exists(testFactory.DecryptedContentFilePath));
            Assert.Equal(testFactory.Content, decryptedContent.Trim());

            // Teardown
            testFactory.Teardown();
        }
예제 #11
0
        public void DecryptFiles(string EncryptedFiles, string Password, string key, string JobNumber, bool csv) // decrypt files
        {
            string ex;

            // check if we are extracting a csv or xls
            if (csv == true)
            {
                ex = ".csv";
            }
            else
            {
                ex = ".xls";
            }


            using (PGP pgp = new PGP())
            {
                string directory = Path.GetDirectoryName(EncryptedFiles);

                pgp.DecryptFile(@EncryptedFiles, Path.Combine(directory, JobNumber + ex), @key, Password);
            }
        }
예제 #12
0
        public void DecryptFile_DecryptEncryptedFileWithDifferentHashAlgorithms(HashAlgorithmTag hashAlgorithmTag)
        {
            // Arrange
            TestFactory testFactory = new TestFactory();

            testFactory.Arrange(KeyType.Known, FileType.Known);
            PGP pgp = new PGP();

            pgp.HashAlgorithmTag = hashAlgorithmTag;

            // Act
            pgp.EncryptFile(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath);
            pgp.DecryptFile(testFactory.EncryptedContentFilePath, testFactory.DecryptedContentFilePath, testFactory.PrivateKeyFilePath, testFactory.Password);
            string decryptedContent = File.ReadAllText(testFactory.DecryptedContentFilePath);

            // Assert
            Assert.True(File.Exists(testFactory.EncryptedContentFilePath));
            Assert.True(File.Exists(testFactory.DecryptedContentFilePath));
            Assert.Equal(testFactory.Content, decryptedContent.Trim());

            // Teardown
            testFactory.Teardown();
        }
 public bool DecryptFile(string inputPath, string outputPath, string privateKeyPath, string privateKeyPassword)
 {
     return(TryExecute(() => crypter.DecryptFile(inputPath, outputPath, privateKeyPath, privateKeyPassword)));
 }
예제 #14
0
        private static void ProcessFiles(Options opts)
        {
            timer.Stop();
            PGP pgp = new PGP();

            // Key generation
            if (opts.KeyGen)
            {
                if (opts.Daemon)
                {
                    Log("Can't generate keys when running as daemon.", LEVEL.Error);
                    Environment.Exit(1);
                }
                if (!File.Exists(opts.KeyPath + PUBLIC_KEY) || !File.Exists(opts.KeyPath + PRIVATE_KEY))
                {
                    try
                    {
                        pgp.GenerateKey(opts.KeyPath + PUBLIC_KEY, opts.KeyPath + PRIVATE_KEY, password: opts.Password);
                    }
                    catch (Exception ex)
                    {
                        Log(ex.ToString(), LEVEL.Error);
                        Environment.Exit(1);
                    }
                    Log("Keypair written to " + opts.KeyPath + "/", LEVEL.Info);
                    Environment.Exit(0);
                }
                else
                {
                    Log("Key files already present, will not overwrite for security reasons. Exiting", LEVEL.Error);
                    Environment.Exit(1);
                }
            }

            // Reviewing Deletions
            if (opts.ReviewDeletions)
            {
                foreach (string x in HashHelper.GetDeletedFiles())
                {
                    Log(x);
                }
                Environment.Exit(0);
            }

            if (opts.ApplyDeletions)
            {
                DeleteFiles(opts, pgp);         // Pgp passed because we need to decrypt the file before deleting.
                Environment.Exit(0);
            }

            // File Handling
            Log("Searching files and directories...");
            string[] files = Directory.GetFiles(opts.Inputdir, "*", SearchOption.AllDirectories);
            string[] dirs  = Directory.GetDirectories(opts.Inputdir, "*", SearchOption.AllDirectories);


            Log("Creating directories...");
            foreach (string dir in dirs)
            {
                try
                {
                    if (!Directory.Exists(dir.Replace(opts.Inputdir, opts.Ouputdir)))
                    {
                        try
                        {
                            Directory.CreateDirectory(dir.Replace(opts.Inputdir, opts.Ouputdir));
                            Log("Created " + dir.Replace(opts.Inputdir, opts.Ouputdir), LEVEL.Info);
                        }
                        catch (Exception ex)
                        {
                            Log(ex.ToString(), LEVEL.Error);
                            Environment.Exit(1);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log(ex.ToString(), LEVEL.Error);
                    Environment.Exit(1);
                }
            }


            Log("Using keyfile: " + opts.KeyPath + PRIVATE_KEY, LEVEL.Info);
            Log("Processing " + files.Count().ToString() + " files.", LEVEL.Info);
            int total = files.Count();
            int count = 1;

            foreach (string file in files)
            {
                Log(count.ToString() + "/" + total.ToString());
                if (opts.Decrypt)
                {
                    Log("Decrypting " + file);
                    try
                    {
                        pgp.DecryptFile(file, opts.Ouputdir + "/" + Path.GetFileName(file).Replace(".pgp", ""), opts.KeyPath + PRIVATE_KEY, opts.Password);
                    }
                    catch (Exception ex)
                    {
                        Log(ex.ToString(), LEVEL.Error);
                    }
                    Log("Wrote " + opts.Ouputdir + "/" + Path.GetFileName(file), LEVEL.Ok);
                }
                else
                {
                    string fileHash = HashHelper.GetHashFromFile(file);
                    if (HashHelper.GetHashFromDb(file) != fileHash)
                    {
                        bool update = false;
                        if (HashHelper.FindDupeHash(fileHash))
                        {
                            Log("Found an existing hash for file: " + file + ", skipping.", LEVEL.Warning);
                        }
                        else
                        {
                            if (HashHelper.FindDupeFileName(file))
                            {
                                update = true;
                                Log("Found another file with the same name, updating hash and re-encrypting.", LEVEL.Info);
                            }
                            try
                            {
                                Log("Encrypting " + file, LEVEL.Info);
                                pgp.EncryptFile(file, file.Replace(opts.Inputdir, opts.Ouputdir) + ".pgp", opts.KeyPath + PUBLIC_KEY);
                                Log("Storing hash " + fileHash + " for " + file, LEVEL.Info);
                                HashHelper.StoreHash(file, fileHash, update);
                                Log("Wrote " + file.Replace(opts.Inputdir, opts.Ouputdir) + ".pgp", LEVEL.Ok);
                            }
                            catch (Exception ex)
                            {
                                Log(ex.ToString(), LEVEL.Error);
                            }
                        }
                    }
                    else
                    {
                        Log("Skipping " + file + " -> Unchanged.");
                    }
                }
                count++;
            }

            // Exit after loop if only used for decryption
            if (opts.Decrypt)
            {
                Environment.Exit(0);
            }

            // Check deletions
            Log("Marking files for deletions...", LEVEL.Info);
            string[] dbFiles = HashHelper.GetDbFilesList();
            foreach (string file in dbFiles)
            {
                if (files.ToList().IndexOf(file) < 0)
                {
                    HashHelper.MarkForDeletion(file);
                    Log("File " + file + " is not in the source directory and was marked for deletion.");
                }
            }

            // Delete
            if (opts.PropagateDeletions)
            {
                DeleteFiles(opts, pgp);
            }

            Log("Complete.", LEVEL.Info);
            timer.Start();
        }
예제 #15
0
        private static void DeleteFiles(Options opts, PGP pgp)
        {
            Log("Deleting removed files...", LEVEL.Info);
            string[] delete = HashHelper.GetDeletedFiles();
            foreach (string f in delete)
            {
                string hash = HashHelper.GetHashFromDb(f);
                HashHelper.DeleteFromDb(f);
                string encFile = opts.Ouputdir + "/" + Path.GetFileName(f) + ".pgp";

                if (File.Exists(encFile))
                {
                    // Create a temp directory for decryption
                    DirectoryInfo dir = null;
                    try
                    {
                        dir = Directory.CreateDirectory("temp");
                    }
                    catch (Exception ex)
                    {
                        Log(ex.ToString(), LEVEL.Error);
                        Environment.Exit(1);
                    }
                    Log("Created temp directory for decryption: " + dir.FullName, LEVEL.Info);

                    // Decrypt and get file hash
                    try
                    {
                        pgp.DecryptFile(encFile, dir.FullName + "/" + Path.GetFileName(f).Replace(".pgp", ""), opts.KeyPath + PRIVATE_KEY, opts.Password);
                    }
                    catch (Org.BouncyCastle.Bcpg.OpenPgp.PgpException pex)
                    {
                        Log("Decrypting exception. (Did you provide the private key passphrase?) " + pex.ToString(), LEVEL.Error);
                        Environment.Exit(1);
                    }
                    catch (Exception ex)
                    {
                        Log(ex.ToString(), LEVEL.Error);
                        Environment.Exit(1);
                    }

                    if (hash == HashHelper.GetHashFromFile(dir.FullName + "/" + Path.GetFileName(f)))
                    {
                        try
                        {
                            File.Delete(encFile);
                        }
                        catch (Exception ex)
                        {
                            Log(ex.ToString(), LEVEL.Error);
                            continue;
                        }
                        Log("Deleted encrpyted file: " + encFile);
                    }
                    else
                    {
                        Log("Hashes of encrypted file is not matching the original. The file will be deleted from the database but not from the disk.", LEVEL.Warning);
                    }

                    //Cleanup
                    try
                    {
                        Directory.Delete(dir.FullName, true);
                    }
                    catch (Exception ex)
                    {
                        Log(ex.ToString(), LEVEL.Error);
                    }
                }
            }
        }
예제 #16
0
        private static void DecryptFileWithPgpKey(string inputFilePath, string outputFilePath)
        {
            EnsurePathParentDirectoryExists(outputFilePath);

            Pgp.DecryptFile(inputFilePath, outputFilePath, _privateKeyPath, "");
        }
예제 #17
0
        static void Main(string[] args)
        {
            using (PGP pgp = new PGP())
            {
                // Generate keys
                pgp.GenerateKey(@"C:\TEMP\keys\public.asc", @"C:\TEMP\keys\private.asc", "*****@*****.**", "password");
                pgp.GenerateKey(@"C:\TEMP\keys\public2.asc", @"C:\TEMP\keys\private2.asc", "*****@*****.**", "password2");
                // Encrypt file
                pgp.EncryptFile(@"C:\TEMP\keys\content.txt", @"C:\TEMP\keys\content__encrypted.pgp", @"C:\TEMP\keys\public.asc", true, true);
                // Encrypt file with multiple keys
                string[] publicKeys = { @"C:\TEMP\keys\public.asc", @"C:\TEMP\keys\public2.asc" };
                pgp.EncryptFile(@"C:\TEMP\keys\content.txt", @"C:\TEMP\keys\content__encrypted_multiple.pgp", publicKeys, true, true);
                // Encrypt and sign file
                pgp.EncryptFileAndSign(@"C:\TEMP\keys\content.txt", @"C:\TEMP\keys\content__encrypted_signed.pgp", @"C:\TEMP\keys\public.asc", @"C:\TEMP\keys\private.asc", "password", true, true);
                // Encrypt and sign multiple file
                pgp.EncryptFileAndSign(@"C:\TEMP\keys\content.txt", @"C:\TEMP\keys\content__encrypted_signed_multiple.pgp", publicKeys, @"C:\TEMP\keys\private.asc", "password", true, true);
                // Decrypt file
                pgp.DecryptFile(@"C:\TEMP\keys\content__encrypted.pgp", @"C:\TEMP\keys\content__decrypted.txt", @"C:\TEMP\keys\private.asc", "password");
                // Decrypt multiple file
                pgp.DecryptFile(@"C:\TEMP\keys\content__encrypted_multiple.pgp", @"C:\TEMP\keys\content__decrypted_multiple.txt", @"C:\TEMP\keys\private.asc", "password");
                pgp.DecryptFile(@"C:\TEMP\keys\content__encrypted_multiple.pgp", @"C:\TEMP\keys\content__decrypted_multiple2.txt", @"C:\TEMP\keys\private2.asc", "password2");
                // Decrypt signed file
                pgp.DecryptFile(@"C:\TEMP\keys\content__encrypted_signed.pgp", @"C:\TEMP\keys\content__decrypted_signed.txt", @"C:\TEMP\keys\private.asc", "password");
                // Decrypt signed multiple file
                pgp.DecryptFile(@"C:\TEMP\keys\content__encrypted_signed_multiple.pgp", @"C:\TEMP\keys\content__decrypted_signed_multiple.txt", @"C:\TEMP\keys\private.asc", "password");
                pgp.DecryptFile(@"C:\TEMP\keys\content__encrypted_signed_multiple.pgp", @"C:\TEMP\keys\content__decrypted_signed_multiple2.txt", @"C:\TEMP\keys\private2.asc", "password2");

                // Encrypt stream
                using (FileStream inputFileStream = new FileStream(@"C:\TEMP\keys\content.txt", FileMode.Open))
                    using (Stream outputFileStream = File.Create(@"C:\TEMP\keys\content__encrypted2.pgp"))
                        using (Stream publicKeyStream = new FileStream(@"C:\TEMP\keys\public.asc", FileMode.Open))
                            pgp.EncryptStream(inputFileStream, outputFileStream, publicKeyStream, true, true);

                // Decrypt stream
                using (FileStream inputFileStream = new FileStream(@"C:\TEMP\keys\content__encrypted2.pgp", FileMode.Open))
                    using (Stream outputFileStream = File.Create(@"C:\TEMP\keys\content__decrypted2.txt"))
                        using (Stream privateKeyStream = new FileStream(@"C:\TEMP\keys\private.asc", FileMode.Open))
                            pgp.DecryptStream(inputFileStream, outputFileStream, privateKeyStream, "password");

                // Encrypt and decrypt streams
                using (Stream inputFileStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("Streaming test message")))
                {
                    using (Stream publicKeyStream = new FileStream(@"C:\TEMP\keys\public.asc", FileMode.Open))
                    {
                        using (Stream encryptedMemoryStream = new MemoryStream())
                        {
                            pgp.EncryptStream(inputFileStream, encryptedMemoryStream, publicKeyStream);
                            encryptedMemoryStream.Seek(0, SeekOrigin.Begin);
                            StreamReader encryptedReader = new StreamReader(encryptedMemoryStream);
                            // Reset stream to beginning
                            encryptedMemoryStream.Seek(0, SeekOrigin.Begin);
                            string encryptedText = encryptedReader.ReadToEnd();
                            Console.WriteLine(encryptedText);

                            // Reset stream to beginning again
                            // Only necessary as stream read to end above for demo output
                            encryptedMemoryStream.Seek(0, SeekOrigin.Begin);

                            using (Stream decryptedMemoryStream = new MemoryStream())
                            {
                                using (Stream privateKeyStream = new FileStream(@"C:\TEMP\keys\private.asc", FileMode.Open))
                                {
                                    pgp.DecryptStream(encryptedMemoryStream, decryptedMemoryStream, privateKeyStream, "password");
                                    decryptedMemoryStream.Seek(0, SeekOrigin.Begin);
                                    StreamReader decryptedReader = new StreamReader(decryptedMemoryStream);
                                    string       decryptedText   = decryptedReader.ReadToEnd();
                                    Console.WriteLine(decryptedText);
                                }
                            }
                        }
                    }
                }

                // Encrypt key and sign stream
                using (Stream inputFileStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("Streaming signed test message")))
                {
                    using (Stream publicKeyStream = new FileStream(@"C:\TEMP\keys\public.asc", FileMode.Open))
                    {
                        using (Stream privateKeyStream = new FileStream(@"C:\TEMP\keys\private.asc", FileMode.Open))
                        {
                            using (Stream encryptedMemoryStream = new MemoryStream())
                            {
                                pgp.EncryptStreamAndSign(inputFileStream, encryptedMemoryStream, publicKeyStream, privateKeyStream, "password");
                                // Reset stream to beginning
                                encryptedMemoryStream.Seek(0, SeekOrigin.Begin);
                                StreamReader encryptedReader = new StreamReader(encryptedMemoryStream);
                                string       encryptedText   = encryptedReader.ReadToEnd();
                                Console.WriteLine(encryptedText);
                            }
                        }
                    }
                }
            }
        }