PGPKeyPair sgnKeyPair = new PGPKeyPair(PGPPublicKey.RSA_SIGN, kpSgn, date);
PGPKeyPair encKeyPair = new PGPKeyPair(PGPPublicKey.RSA_GENERAL, kpEnc, date);
PGPSignatureSubpacketVector unhashedPcks = null;
PGPSignatureSubpacketGenerator svg = new PGPSignatureSubpacketGenerator();
svg.setKeyExpirationTime(true, 86400L * 366 * 2);
svg.setPrimaryUserID(true, true);
int[] encAlgs = {SymmetricKeyAlgorithmTags.AES_256,
SymmetricKeyAlgorithmTags.AES_192,
SymmetricKeyAlgorithmTags.TRIPLE_DES};
svg.setPreferredSymmetricAlgorithms(true, encAlgs);
int[] hashAlgs = {HashAlgorithmTags.SHA1,
HashAlgorithmTags.SHA512,
HashAlgorithmTags.SHA384,
HashAlgorithmTags.SHA256,
HashAlgorithmTags.RIPEMD160};
svg.setPreferredHashAlgorithms(true, hashAlgs);
int[] comprAlgs = {CompressionAlgorithmTags.ZLIB,
CompressionAlgorithmTags.BZIP2,
CompressionAlgorithmTags.ZIP};
svg.setPreferredCompressionAlgorithms(true, comprAlgs);
svg.setFeature(true, Features.FEATURE_MODIFICATION_DETECTION);
svg.setKeyFlags(true, KeyFlags.CERTIFY_OTHER + KeyFlags.SIGN_DATA);
PGPSignatureSubpacketVector hashedPcks = svg.generate();
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION,
sgnKeyPair, identity, PGPEncryptedData.AES_256, passPhrase,
true, hashedPcks, unhashedPcks, new SecureRandom(), "BC");
svg = new PGPSignatureSubpacketGenerator();
svg.setKeyExpirationTime(true, 86400L * 366 * 2);
svg.setKeyFlags(true, KeyFlags.ENCRYPT_COMMS + KeyFlags.ENCRYPT_STORAGE);
svg.setPrimaryUserID(true, false);
svg.setFeature(true, Features.FEATURE_MODIFICATION_DETECTION);
hashedPcks = svg.generate();
keyRingGen.addSubKey(encKeyPair, hashedPcks, unhashedPcks);
byte[] encodedKeyRing = keyRingGen.generatePublicKeyRing().getEncoded();