rsaKp = rsaKpg.generateKeyPair();
PGPKeyPair rsaKeyPair2 = new PGPKeyPair(PGPPublicKey.RSA_GENERAL, rsaKp, new Date());
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsaKeyPair1,
"test", PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");
PGPSecretKeyRing secRing1 = keyRingGen.generateSecretKeyRing();
PGPPublicKeyRing pubRing1 = keyRingGen.generatePublicKeyRing();
keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsaKeyPair2,
"test", PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");
PGPSecretKeyRing secRing2 = keyRingGen.generateSecretKeyRing();
PGPPublicKeyRing pubRing2 = keyRingGen.generatePublicKeyRing();
try
{
PGPPublicKeyRing.insertPublicKey(pubRing1, pubRing2.getPublicKey());
fail("adding second master key (public) should throw an IllegalArgumentException");
}
catch (IllegalArgumentException e)
{
if (!e.getMessage().equals("cannot add a master key to a ring that already has one"))
{
fail("wrong message in public test");
}
}
try
{
PGPSecretKeyRing.insertSecretKey(secRing1, secRing2.getSecretKey());
fail("adding second master key (secret) should throw an IllegalArgumentException");
}
catch (IllegalArgumentException e)
{
if (!e.getMessage().equals("cannot add a master key to a ring that already has one"))