Use GnuPG Tools or C# Code for PGP Encryption and Signature
For PGP encryption and signature, usually we use PGP command line tools for test purpose and finally use C# application for production.
Mine is a Net Core 2.0 console application using NuGet package PgpCore, https://github.com/mattosaurus/PgpCore. PgpCore is based on BouncyCastle.NetCore which supports the standard OpenPGP keys. Here w use the popular GnuPG (GPG) tools to generate OpenPGP key pair.
C:\Program Files (x86)\GnuPG\bin> gpg --full-generate-key
For old versions of GnuPG:
C:\Program Files (x86)\GnuPG\bin> gpg --gen-key
List private keys: gpg --list-secretkey or gpg -K
List and check signatures: gpg --check-sigs
To delete a key pair, please delete private first, then delete public:
Delete a private key: gpg --delete-secret-key keyname
Delete a public key: gpg --delete-key keyname
Please send this public key file to the remote server so that the server can validate our signature.
This private key file will be used by the PgpCore package for file signature.
C:\Program Files (x86)\GnuPG\bin>gpg --sign-key RemoteServersPGPKeyName
C:\Program Files (x86)\GnuPG\bin>gpg --edit-key RemoteServersPGPKeyName (then type trust and quit)
Please note that we don't need to import remote server's public key if we use C# code for encryption and signature.
C:\Program Files (x86)\GnuPG\bin>gpg -r RecipientKeyName -a -u SenderKeyName -s -e -o encryptedAndSignedFile sourceFile
Descrypt:
Decrypt: C:\Program Files (x86)\GnuPG\bin>gpg -d -o destinationFile encryptedFile
Mine is a Net Core 2.0 console application using NuGet package PgpCore, https://github.com/mattosaurus/PgpCore. PgpCore is based on BouncyCastle.NetCore which supports the standard OpenPGP keys. Here w use the popular GnuPG (GPG) tools to generate OpenPGP key pair.
Download and Install GPG for Windows
Download from https://gpg4win.org/download.html. By default the installation will create two folders (here we use command line tools only):- Gpg4Win UI (Kleopatra): C:\Program Files (x86)\Gpg4win
- Command line tools: C:\Program Files (x86)\GnuPG\bin
Generate a GPG Key Pair
For GnuPG 2.2.1 and above:C:\Program Files (x86)\GnuPG\bin> gpg --full-generate-key
For old versions of GnuPG:
C:\Program Files (x86)\GnuPG\bin> gpg --gen-key
Common GPG Commands
List public keys: gpg --list-key or gpg -kList private keys: gpg --list-secretkey or gpg -K
List and check signatures: gpg --check-sigs
To delete a key pair, please delete private first, then delete public:
Delete a private key: gpg --delete-secret-key keyname
Delete a public key: gpg --delete-key keyname
Export GPG Public Key File
C:\Program Files (x86)\GnuPG\bin>gpg --export -a -o PGPPublicKey.asc keynamePlease send this public key file to the remote server so that the server can validate our signature.
Export GPG Private Key File (if using C# code)
C:\Program Files (x86)\GnuPG\bin>gpg --export-secret-key -a -o PGPPrivateKey.asc keynameThis private key file will be used by the PgpCore package for file signature.
Please note that we don't need to export the private key if we use GPG command line tools only.
Import, Sign and Trust Remote Server's GPG Public Key (if using GPG command tools)
C:\Program Files (x86)\GnuPG\bin>gpg --import RemoteServersPGPPublicKeyFilePathC:\Program Files (x86)\GnuPG\bin>gpg --sign-key RemoteServersPGPKeyName
C:\Program Files (x86)\GnuPG\bin>gpg --edit-key RemoteServersPGPKeyName (then type trust and quit)
Encryption and Signature using GPG command tools
Encrypt and Sign:C:\Program Files (x86)\GnuPG\bin>gpg -r RecipientKeyName -a -u SenderKeyName -s -e -o encryptedAndSignedFile sourceFile
Descrypt:
Decrypt: C:\Program Files (x86)\GnuPG\bin>gpg -d -o destinationFile encryptedFile
Encryption and Signature using C# Code
using PgpCore;
using (PGP pgp = new PGP()) {
pgp.EncryptFileAndSign(Source, EncryptedAndSignedFile, RemoteServersPGPPublicKeyFilePath, ClientsPGPPrivateKeyFilePath, ClientsPGPPrivateKeyPassPhrase, Armor?, IntegrityCheck?);
}
I am very grateful you did share your knowledge here. It is an excellent post.Thank you so much for providing such useful content.
ReplyDeleteDigital Signature Certificate
Interesting topic for a blog. I have been searching the Internet for fun and came upon your blog Fabulous post. We are the best provider of digital signature certificate
ReplyDeleteReading your blog is really Amazing. Thanks for this one and expect one more from you.
ReplyDeleteGet class 2 digital signature certificate at a very reasonable price.
Thanks for this blog and it is absolutely fantastic.
ReplyDeleteClass 2 Digital Signature Provider in Noida
Thanks for sharing this. Very useful article.
ReplyDeleteDigital signature Certificate
I am really happy after read this post. Keep blogging.
ReplyDeleteRenew digital signature in Ghaziabad
I'm happy to see your instructive post here and yes I'm going to attempt your tips a debt of gratitude is in order for sharing… Keep Sharing
ReplyDeleteClass 3 digital signature certificate
This was really what i was looking for and i'm glad to come back right here! Thanks for sharing such treasured statistics with us.
ReplyDeleteDigital signature Provider in Delhi
I've been searching for information on this subject for some time. I'm glad this one is so extraordinary. Keep up the brilliant work.
ReplyDeleteDigital signature provider in Delhi
thankyou for sharing these details we will coordinate with you,doing good job guys
ReplyDeletehttps://www.99digitalsignature.com
ReplyDeleteI want to thank you. Because for this great post you really deserve a big thumbs up.
digital signature provider in Gurgaon
Thank you for all the knowledge that you share, great article. I was extremely interested in the post, and it's impressive.
ReplyDeleteprinting company sydney
Pretty! This was an extremely wonderful post. I'm thankful that you're sharing useful and valuable information for all us.
ReplyDeleteShadi dresses design
Here are also useful links
Deleteshadi dresses for girl
pakistani wedding dresses
Awesome article on blog commenting, keep the good work Thank you.Digital Signature In Noida
ReplyDeleteFirst of all thanks to the blogger for sharing and giving useful information. Buy Digital Signature in Chennai
ReplyDeleteAwesome article on blog commenting, keep the good work Thank you. Get Digital Signature in Ghaziabad
ReplyDeleteThis post is really insightful; it has helped me understand so many things.Best Digital Signature Services In Faridabad
ReplyDeleteAwesome article on blog commenting, keep the good work Thank you.Best Digital Signature Agency in Ghaziabad
ReplyDeleteThanks for the wonderful post. I've been looking around the web for this type of information and finally found it.Buy Digital Signature in Chennai
ReplyDeleteHappy to see your blog as it is just what I’ve looking for. I am looking forward to another great article from you.Best Digital Signature Services in Faridabad
ReplyDeleteThank you for describing in detail about blog commenting. It is a valuable tool.Apply Digital Signature in Jalandhar
ReplyDeleteThank you for this helpful article! I have a question though. How many comments should I post per day.Buy Digital Signature In Siwan
ReplyDeleteThanks for posting such an informative article.Apply Digital Signature in Gopalganj
ReplyDeleteThank you very much for your valuable information. Digital Signature in Rajkot
ReplyDeleteVery well constructed about blog commenting. Blog commenting plays a good role in SEO in fact approving the comments is the biggest achievement. Renew Detective Signature Online
ReplyDeleteThank you for describing in detail about blog commenting. It is a valuable tool. Digital Signature in Kolkata
ReplyDeleteThanks for this useful article. Digital Signature Certificate For Icegate
ReplyDeleteThanks for sharing the relevant information with us…It are good tool for search blog comments rapidly…...Digital Signature in aligarh
ReplyDelete