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