Has anyone successfully used the BouncyCastle OpenPGP library to read a public keyring?
Here's my attempt:
File publicKeyFile = new File(System.getProperty("user.home"), ".gnupg/pubring.gpg");
Security.addProvider(new BouncyCastleProvider());
FileInputStream in = new FileInputStream(publicKeyFile);
PGPObjectFactory objectFactory = new PGPObjectFactory(in);
while (true)
{
Object object = objectFactory.nextObject();
if (object instanceof PGPPublicKeyRing)
{
PGPPublicKeyRing keyRing = (PGPPublicKeyRing) object;
}
}
in.close();
But I get an error:
java.io.IOException: unknown object in stream 12
at org.bouncycastle.openpgp.PGPObjectFactory.nextObject(PGPObjectFactory.java:109)
at net.xaoza.pgpvis.Test.main(Test.java:36)
What am I doing wrong? I've stared at this for ages, and can't yet see anything out of place.