0
votes

New to PGP and I'm trying to encrypt a file through a C# console app. In my research it sounds as though BouncyCastle is one of the more popular ones to use. I found the following article and it looks like it would work just fine except that I only have the public key. http://burnignorance.com/c-coding-tips/pgp-encryption-decryption-in-c/

Looking around more, I have not found any examples where I can use just the public key to encrypt. All the examples I've come across want to use public key, private key, and password.

3
From my understanding the person decrypting needs the private key. In my case a different group will be decrypting so they need to have the private key and they give me the public key used to encrypt with. So, I only have the public key.Caverman

3 Answers

0
votes

I found a GitHub file that should get you VERY close to what you want. It gives you both the Encrypt (with public key) and Decrypt (with private key) methods. It uses the Bouncy Castle API, using the AES algorithm.

https://gist.github.com/dziwoki/cc41b523c2bd43ee646b957f0aa91943

0
votes

The main way PGP is used, is where you encrypt with the receivers public key, and sign the message with your privat key. Receiver can then decrypt with his privat key, and verify the signature with your public key. The password is used for the private key.

This setup is a designed decision taken when designing PGP, to live up to the name PGP - Pretty Good Privacy.

0
votes

I'm also new to working on PGP with C#, and I'd suggest using the PgpCore project, which makes working with Bouncy Castle easier. There's a method to do exactly what you desire. Something like this:

using (var pgp = new PGP())
{
    await pgp.EncryptFileAsync(@"C:\TEMP\unencrypted-input.txt", @"C:\TEMP\encrypted-output.pgp", @"C:\TEMP\public.asc");
}

See https://github.com/mattosaurus/PgpCore#encrypt for more options.