List of usage examples for org.bouncycastle.openpgp PGPPublicKeyRingCollection getKeyRings
public Iterator<PGPPublicKeyRing> getKeyRings(String userID, boolean matchPartial) throws PGPException
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; }