Java 类org.bouncycastle.openpgp.bc.BcPGPSecretKeyRingCollection 实例源码

项目:nomulus    文件:DummyKeyringModule.java   
/** Always returns a {@link InMemoryKeyring} instance. */
@Provides
static Keyring provideKeyring() {
  PGPKeyPair dummyKey;
  try (InputStream publicInput = PGP_PUBLIC_KEYRING.openStream();
      InputStream privateInput = PGP_PRIVATE_KEYRING.openStream()) {
    PGPPublicKeyRingCollection publicKeys =
        new BcPGPPublicKeyRingCollection(PGPUtil.getDecoderStream(publicInput));
    PGPSecretKeyRingCollection privateKeys =
        new BcPGPSecretKeyRingCollection(PGPUtil.getDecoderStream(privateInput));
    dummyKey = lookupKeyPair(publicKeys, privateKeys, EMAIL_ADDRESS, ENCRYPT_SIGN);
  } catch (PGPException | IOException e) {
    throw new VerifyException("Failed to load PGP keys from jar", e);
  }
  // Use the same dummy PGP keypair for all required PGP keys -- a real production system would
  // have different values for these keys.  Pass dummy values for all Strings.
  return new InMemoryKeyring(
      dummyKey,
      dummyKey,
      dummyKey.getPublicKey(),
      dummyKey,
      dummyKey.getPublicKey(),
      "not a real key",
      "not a real key",
      "not a real password",
      "not a real login",
      "not a real password",
      "not a real login",
      "not a real credential",
      "not a real key");
}
项目:packagedrone    文件:PgpHelper.java   
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;
            }

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

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

            return key;
        }
    }

    return null;
}
项目:package-drone    文件:PgpHelper.java   
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;
            }

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

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

            return key;
        }
    }

    return null;
}
项目:packagedrone    文件:PgpHelper.java   
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 );
}