Example usage for org.bouncycastle.openpgp.bc BcPGPSecretKeyRingCollection getKeyRings

List of usage examples for org.bouncycastle.openpgp.bc BcPGPSecretKeyRingCollection getKeyRings

Introduction

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

Prototype

public Iterator<PGPSecretKeyRing> getKeyRings() 

Source Link

Document

return the secret key rings making up this collection.

Usage

From source file:de.dentrassi.pm.signing.pgp.PgpHelper.java

License:Open Source License

public static PGPSecretKey loadSecretKey(final InputStream input, final String keyId)
        throws IOException, PGPException {
    final long keyIdNum = Long.parseUnsignedLong(keyId, 16);

    final BcPGPSecretKeyRingCollection keyrings = new BcPGPSecretKeyRingCollection(
            PGPUtil.getDecoderStream(input));

    final Iterator<?> keyRingIter = keyrings.getKeyRings();
    while (keyRingIter.hasNext()) {
        final PGPSecretKeyRing secretKeyRing = (PGPSecretKeyRing) keyRingIter.next();

        final Iterator<?> secretKeyIterator = secretKeyRing.getSecretKeys();
        while (secretKeyIterator.hasNext()) {
            final PGPSecretKey key = (PGPSecretKey) secretKeyIterator.next();

            if (!key.isSigningKey()) {
                continue;
            }/*w w  w . j  a  va2  s.  c o  m*/

            final long shortId = key.getKeyID() & 0xFFFFFFFFL;

            if (key.getKeyID() != keyIdNum && shortId != keyIdNum) {
                continue;
            }

            return key;
        }
    }

    return null;
}

From source file:org.eclipse.packagedrone.repo.signing.pgp.PgpHelper.java

License:Open Source License

public static Stream<PGPKeyRing> streamKeyring(final InputStream input) throws IOException, PGPException {
    final BcPGPSecretKeyRingCollection keyrings = new BcPGPSecretKeyRingCollection(
            PGPUtil.getDecoderStream(input));

    final Iterator<?> keyRingIter = keyrings.getKeyRings();

    final Stream<?> s = StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(keyRingIter, Spliterator.ORDERED), false);

    return s.map(o -> (PGPKeyRing) o);
}