Introduction
PGP stands for “Pretty Good Privacy,” and it’s most often used for sending encrypted messages between two people. Pretty Good Privacy (PGP) is a data encryption and decryption computer program that provides cryptographic privacy and authentication for data communication. PGP is often used for signing, encrypting, and decrypting texts, emails, files, directories, and whole disk partitions and to increase the security of e-mail communications.
I would recommend that you please find about cryptography before starting PGP works.
What is cryptography
Cryptography is the science of using mathematics to encrypt and decrypt data. Cryptography enables you to store sensitive information or transmit it across insecure networks (like the Internet) so that it cannot be read by anyone except the intended recipient.
How does Cryptography work?
- Plain text --> Message Encrypted Security Algorithms [Cryptography] --> Cipher text.
- Cipher text --> [Cryptography] Message Encrypted Security Algorithms --> Plain text.
PGP Conceptual view

Flow of Control

The following series of mechanical steps explains how to achieve PGP process in C#.NET.
Step 1: Please enter the Signature to get the valid Keys which is private and public keys to encrypt plain text to PGP Encrypted text.

Code Snippet
private void button1_Click(object sender, EventArgs e)
{
string signature = textBox3.Text;
textBox1.Text = PGPKEYS.PGPKeyrings.PrivateKey(signature);
textBox2.Text = PGPKEYS.PGPKeyrings.PublicKey(signature);
}
Keys will be now:

Step 2: PGP Encryption has happened with a combination of Signature + Private KEY + Public Key:

private void button2_Click(object sender, EventArgs e)
{
PGPEncryptionText.Text = "";
try
{
PGPEncryptionText.Text = PGPKEYS.PGPKeyrings.PGPEncryption(new PGPKEYS.PGPProperties
{
private key = textBox1.Text,
public key = textBox2.Text,
signature = textBox3.Text
}, PlainText.Text.ToString());
}
catch (Exception ex)
{
MessageBox.Show("Wrong Keys Found");
}
}
Find Cipher Text now.
Step 3: In this we can get plain text from cipher text.

private void button3_Click(object sender, EventArgs e)
{
PGPDecryptionText.Text = "";
try
{
PGPDecryptionText.Text = PGPKEYS.PGPKeyrings.PGPDecryption(new PGPKEYS.PGPProperties
{
private key = textBox1.Text,
public key = textBox2.Text,
signature = textBox3.Text
}, PGPEncryptionText.Text.ToString());
}
catch (Exception ex)
{
MessageBox.Show("Wrong Keys Found");
}
}
Step 4: Assertion.
Imagine I changed Sign p.m@ruthi to p.m@ruthipall, but plain text will notbe produced if the keys are same. Your Signature Keys must be same, then only will Decryption happen.

Text with Actual Sign.
Decryption checks Signature with keys.

References

YuppskiPosted Nov 22, 2023, 10:10 AM
Hi Maruthi, The link for the source code appears to not be working. Could you supply another alternative link? Thanks
Gurpreet kaurPosted Apr 9, 2019, 5:44 AM
I am not getting source code from below location https://code.msdn.microsoft.com/vstudio/Pretty-Good-Privacy-using-4f473c67/sourcecode?fileId=148103&pathId=1897089268
Rifat AhmedPosted Aug 10, 2018, 9:03 AM
Hi Maruthi, Can I encrypt pdf/doc/image file using PGP encryption? Can you please give me a sample code for that? -Thanks in advance :)
Rohan ChapkePosted Dec 15, 2017, 7:14 PM
Hello, I didn't find below methods PGPKEYS.PGPKeyrings.PrivateKey(signature); PGPKEYS.PGPKeyrings.PublicKey(signature); is there any way to get Private/Public key without saving keys
Pham TrungPosted Oct 16, 2017, 12:46 PM
This is not right with the PGP concept, the Private key should be used to decrypt only, the Public key is used to encrypt. It means that you can send Public key to your partner to encrypt data, and use your Private key to decrypt data, only you should know about Private Key.
nguyen truongPosted Sep 21, 2017, 12:56 AM
Where is source? i need please help me
Ibrahim afifiPosted Jul 18, 2017, 9:03 AM
Hi Maruthi, you are using PGPKEYS , What is this ?
s dPosted Jun 29, 2017, 9:56 AM
Hi Maruthi, Nice examples...thanks for this.. just a question though, our client provided us only private key file to encrypt file before sending it to them ? your c# example expects public key, private key and passphrase... can we not encrypt without public key and passphrase or at least without passphrase ? thanks Satish
sudharshan ssPosted Jun 20, 2017, 2:32 AM
Nice explaination bro..and thanks for the article provided
Sr KarthigaPosted Feb 17, 2016, 8:20 AM
good one
Sr KarthigaPosted Feb 17, 2016, 8:19 AM
Nice explanation
Santhakumar MunuswamyPosted Jan 26, 2016, 1:02 AM
Thanks for nice article
Humayun Kabir MamunPosted Jan 25, 2016, 10:37 PM
Nice...
Ankur MistryPosted Jan 25, 2016, 10:34 PM
Very nice, thanks for sharing
Jaco ZwartsPosted Jan 25, 2016, 2:11 PM
Really good thank you for sharing
Mubarak AhmadPosted Jan 25, 2016, 9:15 AM
Good one...
Mahesh ChandPosted Jan 25, 2016, 8:54 AM
A good one Maruthi. Encryption has become a vital part of communication today. Question - Does the private key has to be stored on local device (computer, tablet, or phone)? Does every user gets his/her own private key? Decryption has to be done on local device. Also how about size difference of encrypted data compared to original?