Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Reading a GPG keyring using BouncyCastle OpenPGP

843810Dec 12 2004 — edited Dec 12 2004
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 9 2005
Added on Dec 12 2004
2 comments
1,196 views