I created PGP public and private keys using org.bouncycastle.openpgp.PGPKeyRingGenerator . After making the changes suggested by GregS, the public key is a .asc file, and the private key is a .skr file. I need to first distribute the public key to Thunderbird users, and then to Outlook users and other email clients. I read these instructions for getting the public key in thunderbird , but the instructions simply specify the .asc extension without specifying the contents / structure of the .asc .
How do I configure my (modified?) Code below to create a public key that can be used by remote Thunderbird users to send encrypted messages, which can then be decrypted with my private key, also generated (modified?) Code below? The accepted answer will include step-by-step instructions not only to make the necessary changes to the code below, but also to configure each remote Thunderbird user to use the prepared public key below to send emails that can be decrypted with the private key in my application created below (modified ?) code.
Here is my first key generation code project:
import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.math.BigInteger; import java.security.SecureRandom; import java.util.Date; import org.bouncycastle.bcpg.ArmoredOutputStream; import org.bouncycastle.bcpg.HashAlgorithmTags; import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags; import org.bouncycastle.bcpg.sig.Features; import org.bouncycastle.bcpg.sig.KeyFlags; import org.bouncycastle.crypto.generators.RSAKeyPairGenerator; import org.bouncycastle.crypto.params.RSAKeyGenerationParameters; import org.bouncycastle.openpgp.PGPEncryptedData; import org.bouncycastle.openpgp.PGPKeyPair; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPKeyRingGenerator; import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator; import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor; import org.bouncycastle.openpgp.operator.PGPDigestCalculator; import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyEncryptorBuilder; import org.bouncycastle.openpgp.operator.bc.BcPGPContentSignerBuilder; import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider; import org.bouncycastle.openpgp.operator.bc.BcPGPKeyPair; public class RSAGen { public static void main(String args[]) throws Exception { char pass[] = {'h', 'e', 'l', 'l', 'o'}; PGPKeyRingGenerator krgen = generateKeyRingGenerator(" alice@example.com ", pass);
When I run the above code to create a .asc file and then try to import the .asc file into Thunderbird, I get the following error screen:

Please note that I did not install GnuPG on my CentOS 7 computer.
In addition, you can easily recreate this problem on your own machine, because Thunderbird is free. You can download thunderbird this link for free . Alternatively, on my CentOS 7 machine, I downloaded Thunderbird using yum install thunderbird . You can download bouncy castle by adding the following to your pom.xml :
<dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcpg-jdk15on</artifactId> <version>1.51</version> </dependency>
EDIT. # 1:
To ask JRichardSnape questions, I found that maven should also automatically load the org.bouncycastle.crypto library, because it is a dependency on bcpg-jdk15on . JRichardSnape is true that RSAKeyGenerationParameters and RSAKeyPairGenerator not in the manual download bcpg-jdk15on.jar . (Note: versions in links may be inactive.) However, both classes are in maven's automated download, which is obtained from the same dependency fragment from pom.xml shown above. I say this because there are no other bouncycastle dependencies in my pom.xml . I am using Java 7.
Eclipse describes two classes imported as:
import org.bouncycastle.crypto.params.RSAKeyGenerationParameters; import org.bouncycastle.crypto.generators.RSAKeyPairGenerator;
I added all import statements from RSAGen.java to the code segment in my OP above. I think the problem may be due to the need for a name / signature for the key.
The following links result from this error:
Convert userId to UTF8 before creating signature # 96
non-ascii characters in name field # 92
Cannot import PGP certificate into keychain
EDIT No. 2
According to @JRichardSnape's advice, I tried Enigmail->Key management ->File ->Import keys from file . This led to the following dialog box, which appears to indicate that although the key was imported, the key was not signed. Thus, it seems that there is no name or email address associated with the imported .asc file. In addition, the key also does not appear in the EnigMail key list.

EDIT No. 3
Using gpg --gen-key , I was able to get the CentOS 7 terminal to create a key pair, including the public key, which I could successfully import into Thunderbird, so that Thunderbird can now associate the gpg-public key published via the terminal with the intended email recipient . But when I take all the steps to send an encrypted email from Thunderbird using a public key, the email and its attachments, however, arrive unencrypted. The steps I took to send an encrypted public key letter from a remote Thunderbird to a private key server are described in this SuperUser publication .
Given that gpg --gen-key seems to work, the main problem right now seems to be Thunderbird part of this generosity issue. In the previous paragraph, I posted great progress in resolving the Thunderbird question in the SuperUser question. Your help in answering this will be of great importance in answering this question.
EDIT # 4
I still cannot get the bouncycastle key to import into Thunderbird. However, when I use the keys created on the CentOS 7 terminal using gpg --gen-key , I can follow these steps:
1.) I configured my Thunderbird to manage another (second) email account I have not been using. 2.) I then created a gpg key for that second account and configured encryption for that second account in Thunderbird. 3.) I sent an encrypted email containing an attachment from the first Thunderbird account to the second Thunderbird account. 4.) I was able to see that the attachment remained encrypted in the second account inbox until I used the recipient key passphrase to decrypt it.
My CentOS 7 server still creates unencrypted attachments when I send it an email from the same "first" Thunderbird account, as described in this edit. I'm trying to determine if this is due to some kind of "automatic decryption" in dovecot / postfix / mailx / gpg on a CentOS 7 server or is it related to some settings in Thunderbird sender. I am studying this.