Example usage for org.bouncycastle.openpgp PGPSecretKeyRingCollection getKeyRings

List of usage examples for org.bouncycastle.openpgp PGPSecretKeyRingCollection getKeyRings

Introduction

In this page you can find the example usage for org.bouncycastle.openpgp PGPSecretKeyRingCollection getKeyRings.

Prototype

public Iterator<PGPSecretKeyRing> getKeyRings(String userID, boolean matchPartial) throws PGPException 

Source Link

Document

Return an iterator of the key rings associated with the passed in userID.

Usage

From source file:org.opentestsystem.delivery.testreg.transformer.GPGEncryptor.java

License:Open Source License

@SuppressWarnings("unchecked")
public PGPSecretKey findTestRegSecretKey() throws IOException, PGPException {

    // get private key for the running test reg
    InputStream secretKeyringInputStream = getStreamForPath(secretKeyringLocation);

    PGPSecretKeyRingCollection pgpSecretkeyringCollection = new PGPSecretKeyRingCollection(
            PGPUtil.getDecoderStream(secretKeyringInputStream));

    Iterator<PGPSecretKeyRing> secretKeyRingItr = pgpSecretkeyringCollection.getKeyRings(testRegSecretKeyUserId,
            true);//  w  ww .  ja v a 2s.c o m

    PGPSecretKey testRegSecretKey = null;

    while (secretKeyRingItr.hasNext()) {
        PGPSecretKeyRing secretKeyRing = secretKeyRingItr.next();

        Iterator<PGPSecretKey> secretKeyItr = secretKeyRing.getSecretKeys();

        while (secretKeyItr.hasNext()) {
            PGPSecretKey secretKey = secretKeyItr.next();

            if (secretKey.isSigningKey()) {
                testRegSecretKey = secretKey;
                break;
            }
        }

    }

    return testRegSecretKey;
}