Skip to content
.NET Core class library for using PGP
Branch: master
Clone or download
Latest commit 31479ef Sep 18, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
PgpCore.Tests Fix encrypt test Sep 18, 2019
PgpCore Update assembly file version Sep 18, 2019
.gitattributes Add .gitignore and .gitattributes. Jun 2, 2017
.gitignore Add .gitignore and .gitattributes. Jun 2, 2017
LICENSE Create LICENSE Feb 10, 2018
PgpCore.sln Add unit tests May 6, 2019 Update Aug 20, 2019


A .NET Core class library for using PGP.

This is based on ChoPGP but updated to .NET Core framework and to add in a missing utilities class.


To use PgpCore in your C# project, you can either download the PgpCore C# .NET libraries directly from the Github repository or, if you have the NuGet package manager installed, you can grab them automatically.

PM> Install-Package PgpCore

Once you have the PgpCore libraries properly referenced in your project, you can include calls to them in your code.

Add the following namespaces to use the library:

using PgpCore;


BouncyCastle.NetCore (>=

Microsoft.NETCore.App (>= 1.1.2)


This is intended for usage in .NET Core projects. For further examples see the tests.

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 file with multiple keys
		string[] publicKeys = Directory.GetFiles("C:\TEMP\keys\", "*.asc);
                pgp.EncryptFile(@"C:\TEMP\keys\content.txt", @"C:\TEMP\keys\content__encrypted.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);
                // 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");

A good resource for generating keys and messages is PGP Key Generator.

You can’t perform that action at this time.