Example usage for org.bouncycastle.openpgp PGPPublicKeyRingCollection getKeyRings

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

Introduction

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

Prototype

public Iterator<PGPPublicKeyRing> 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 PGPPublicKey findLandingZonePublicKey(DwConfigType configType) throws PGPException, IOException {
    // get public key for the landing zone

    String lzPubKeyUserId = null;

    if (configType == DwConfigType.SBAC) {
        lzPubKeyUserId = dwConfigs.getSbacConfig().getLzPubKeyUserid();
    } else {/*w  w  w  . jav a  2s .c  o m*/
        lzPubKeyUserId = dwConfigs.getLocalConfig().getLzPubKeyUserid();
    }

    InputStream publicKeyringInputStream = getStreamForPath(publicKeyringLocation);

    PGPPublicKeyRingCollection pgpPubkeyringCollection = new PGPPublicKeyRingCollection(
            PGPUtil.getDecoderStream(publicKeyringInputStream));

    Iterator<PGPPublicKeyRing> pubkeyringItr = pgpPubkeyringCollection.getKeyRings(lzPubKeyUserId, true);

    PGPPublicKey landingZonePubKey = null;

    while (pubkeyringItr.hasNext()) {

        PGPPublicKeyRing keyring = pubkeyringItr.next();
        Iterator<PGPPublicKey> pubkeyItr = keyring.getPublicKeys();

        while (pubkeyItr.hasNext()) {

            PGPPublicKey pubkey = pubkeyItr.next();

            if (pubkey.isEncryptionKey()) {
                landingZonePubKey = pubkey;
                break;
            }

        }

    }

    return landingZonePubKey;
}