PGPSignatureSubpacketVector hashedPcks = svg.generate();
PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION,
sgnKeyPair, identity,
sha1Calc, hashedPcks, unhashedPcks, new JcaPGPContentSignerBuilder(sgnKeyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).setProvider("BC").build(passPhrase));
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();
PGPPublicKeyRing keyRing = new PGPPublicKeyRing(encodedKeyRing, new JcaKeyFingerprintCalculator());
for (Iterator it = keyRing.getPublicKeys(); it.hasNext();)
{
PGPPublicKey pKey = (PGPPublicKey)it.next();
PGPSignatureGenerator keySigGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(PGPPublicKey.RSA_SIGN, HashAlgorithmTags.SHA1).setProvider("BC"));
if (pKey.isMasterKey())
{
keySigGen.init(PGPSignature.POSITIVE_CERTIFICATION, sgnKeyPair.getPrivateKey());
}