Java 类org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator 实例源码

项目:base    文件:PGPEncryptionUtil.java   
private static PGPLiteralData asLiteral( final byte[] message, final InputStream secretKeyRing,
                                         final String secretPwd ) throws IOException, PGPException
{
    PGPPrivateKey key = null;
    PGPPublicKeyEncryptedData encrypted = null;
    final PGPSecretKeyRingCollection keys =
            new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( secretKeyRing ),
                    new JcaKeyFingerprintCalculator() );
    for ( final Iterator<PGPPublicKeyEncryptedData> i = getEncryptedObjects( message );
          ( key == null ) && i.hasNext(); )
    {
        encrypted = i.next();
        key = getPrivateKey( keys, encrypted.getKeyID(), secretPwd );
    }
    if ( key == null )
    {
        throw new IllegalArgumentException( "secret key for message not found." );
    }
    final InputStream stream = encrypted
            .getDataStream( new JcePublicKeyDataDecryptorFactoryBuilder().setProvider( provider ).build( key ) );
    return asLiteral( stream );
}
项目:base    文件:PGPEncryptionUtil.java   
@SuppressWarnings( "unchecked" )
private static Iterator<PGPPublicKeyEncryptedData> getEncryptedObjects( final byte[] message ) throws IOException
{
    try
    {
        final PGPObjectFactory factory =
                new PGPObjectFactory( PGPUtil.getDecoderStream( new ByteArrayInputStream( message ) ),
                        new JcaKeyFingerprintCalculator() );
        final Object first = factory.nextObject();
        final Object list = ( first instanceof PGPEncryptedDataList ) ? first : factory.nextObject();
        return ( ( PGPEncryptedDataList ) list ).getEncryptedDataObjects();
    }
    catch ( IOException e )
    {
        throw new IOException( e );
    }
}
项目:saveOrganizer    文件:KeyIO.java   
public static PGPPublicKey readPublicKey(InputStream in)
   throws IOException, PGPException {
in = PGPUtil.getDecoderStream(in);

PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(in, new JcaKeyFingerprintCalculator() );
Iterator rIt = pgpPub.getKeyRings();

while (rIt.hasNext()) {
   PGPPublicKeyRing kRing = (PGPPublicKeyRing) rIt.next();
   Iterator kIt = kRing.getPublicKeys();

   while (kIt.hasNext()) {
       PGPPublicKey k = (PGPPublicKey) kIt.next();

       if (k.isEncryptionKey()) {
           return k;
       }
   }
}

throw new IllegalArgumentException(
       "Can't find encryption key in key ring.");
}
项目:react-native-pgp    文件:PGPUtils.java   
static PGPSecretKey getSecretKey(String privateKeyData) throws IOException, PGPException {
  PGPPrivateKey privKey = null;
  try (InputStream privStream = new ArmoredInputStream(new ByteArrayInputStream(privateKeyData.getBytes("UTF-8")))) {
    PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(privStream), new JcaKeyFingerprintCalculator());
    Iterator keyRingIter = pgpSec.getKeyRings();
    while (keyRingIter.hasNext()) {
      PGPSecretKeyRing keyRing = (PGPSecretKeyRing)keyRingIter.next();
      Iterator keyIter = keyRing.getSecretKeys();
      while (keyIter.hasNext()) {
        PGPSecretKey key = (PGPSecretKey)keyIter.next();

        if (key.isSigningKey()) {
          return key;
        }
      }
    }
  }
  throw new IllegalArgumentException("Can't find signing key in key ring.");
}
项目:base    文件:PGPKeyHelper.java   
public static PGPPublicKey readPublicKey( InputStream is ) throws IOException, PGPException
{
    PGPPublicKeyRingCollection pgpPub =
            new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( is ), new JcaKeyFingerprintCalculator() );

    Iterator keyRingIter = pgpPub.getKeyRings();

    while ( keyRingIter.hasNext() )
    {
        PGPPublicKeyRing keyRing = ( PGPPublicKeyRing ) keyRingIter.next();
        Iterator keyIter = keyRing.getPublicKeys();

        while ( keyIter.hasNext() )
        {
            PGPPublicKey key = ( PGPPublicKey ) keyIter.next();

            if ( key.isEncryptionKey() )
            {
                return key;
            }
        }
    }

    throw new IllegalArgumentException( "Can't find encryption key in key ring." );
}
项目:base    文件:PGPKeyHelper.java   
private static PGPSecretKey readSecretKey( InputStream is ) throws IOException, PGPException
{
    PGPSecretKeyRingCollection pgpSec =
            new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( is ), new JcaKeyFingerprintCalculator() );
    Iterator keyRingIter = pgpSec.getKeyRings();

    while ( keyRingIter.hasNext() )
    {
        PGPSecretKeyRing keyRing = ( PGPSecretKeyRing ) keyRingIter.next();
        Iterator keyIter = keyRing.getSecretKeys();

        while ( keyIter.hasNext() )
        {
            PGPSecretKey key = ( PGPSecretKey ) keyIter.next();

            if ( key.isSigningKey() )
            {
                return key;
            }
        }
    }

    throw new IllegalArgumentException( "Can't find signing key in key ring." );
}
项目:nexus-repository-apt    文件:AptSigningFacet.java   
private PGPSecretKey readSecretKey() throws IOException, PGPException {
  PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
      PGPUtil.getDecoderStream(new ByteArrayInputStream(config.keypair.getBytes())),
      new JcaKeyFingerprintCalculator());

  Iterator<PGPSecretKeyRing> keyRings = pgpSec.getKeyRings();
  while (keyRings.hasNext()) {
    PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRings.next();

    Iterator<PGPSecretKey> keys = keyRing.getSecretKeys();
    while (keys.hasNext()) {
      PGPSecretKey key = (PGPSecretKey) keys.next();

      if (key.isSigningKey()) {
        return key;
      }
    }
  }

  throw new IllegalStateException("Can't find signing key in key ring.");
}
项目:jerkar    文件:PgpUtils.java   
private static List<PGPSecretKeyRing> extractSecrectKeyRings(InputStream inputStream) {

        InputStream decodedInput;
        try {
            decodedInput = PGPUtil.getDecoderStream(inputStream);
        } catch (final IOException e) {
            throw JkUtilsThrowable.unchecked(e);
        }
        final KeyFingerPrintCalculator fingerPrintCalculator = new JcaKeyFingerprintCalculator();
        final InnerPGPObjectFactory pgpFact = new InnerPGPObjectFactory(decodedInput,
                fingerPrintCalculator);
        PGPSecretKeyRing secKeyRing;
        final List<PGPSecretKeyRing> result = new LinkedList<>();
        while ((secKeyRing = pgpFact.nextSecretKey()) != null) {
            result.add(secKeyRing);
        }
        return result;
    }
项目:geocaching    文件:PublicKeyCreator.java   
public PGPPublicKey createKeyFrom(InputStream in) throws IOException, PGPException {

    InputStream pgpData = PGPUtil.getDecoderStream(in);

    PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(
            PGPUtil.getDecoderStream(pgpData), new JcaKeyFingerprintCalculator());

    Iterator keyRingIter = pgpPub.getKeyRings();
    while (keyRingIter.hasNext())
    {
        PGPPublicKeyRing keyRing = (PGPPublicKeyRing)keyRingIter.next();

        Iterator keyIter = keyRing.getPublicKeys();
        while (keyIter.hasNext())
        {
            PGPPublicKey key = (PGPPublicKey)keyIter.next();

            if (key.isEncryptionKey())
            {
                return key;
            }
        }
    }
    throw new IllegalArgumentException("Can't find encryption key in key ring.");
}
项目:bouncycastle    文件:PGPCryptoTools.java   
public static final List<String> listCertifications(File publicKeyFile) throws IOException {
        FileInputStream keyInputStream = new FileInputStream(publicKeyFile);
        List<String> keyIds = new ArrayList<String>();

        PGPPublicKeyRing pgpPubRing = new PGPPublicKeyRing(PGPUtil.getDecoderStream(keyInputStream), new JcaKeyFingerprintCalculator());
        PGPPublicKey pubKey = pgpPubRing.getPublicKey();

        @SuppressWarnings("unchecked")
        Iterator<PGPSignature> sigIter = pubKey.getSignatures();
        while (sigIter.hasNext()) {
                PGPSignature pgpSig = sigIter.next();
                long keyId = pgpSig.getKeyID();
                keyIds.add(Long.toHexString(keyId).toUpperCase());
        }

        return keyIds;
}
项目:CryptMeme    文件:PGPECDHTest.java   
public void performTest()
    throws Exception
{
    PGPUtil.setDefaultProvider("BC");

    //
    // Read the public key
    //
    PGPPublicKeyRing        pubKeyRing = new PGPPublicKeyRing(testPubKey, new JcaKeyFingerprintCalculator());

    doBasicKeyRingCheck(pubKeyRing);

    //
    // Read the private key
    //
    PGPSecretKeyRing        secretKeyRing = new PGPSecretKeyRing(testPrivKey, new JcaKeyFingerprintCalculator());

    testDecrypt(secretKeyRing);

    encryptDecryptTest();

    generate();
}
项目:irma_future_id    文件:PGPECDHTest.java   
public void performTest()
    throws Exception
{
    PGPUtil.setDefaultProvider("BC");

    //
    // Read the public key
    //
    PGPPublicKeyRing        pubKeyRing = new PGPPublicKeyRing(testPubKey, new JcaKeyFingerprintCalculator());

    doBasicKeyRingCheck(pubKeyRing);

    //
    // Read the private key
    //
    PGPSecretKeyRing        secretKeyRing = new PGPSecretKeyRing(testPrivKey, new JcaKeyFingerprintCalculator());

    generate();
}
项目:bc-java    文件:PGPECDHTest.java   
public void performTest()
    throws Exception
{
    PGPUtil.setDefaultProvider("BC");

    //
    // Read the public key
    //
    PGPPublicKeyRing        pubKeyRing = new PGPPublicKeyRing(testPubKey, new JcaKeyFingerprintCalculator());

    doBasicKeyRingCheck(pubKeyRing);

    //
    // Read the private key
    //
    PGPSecretKeyRing        secretKeyRing = new PGPSecretKeyRing(testPrivKey, new JcaKeyFingerprintCalculator());

    generate();
}
项目:gpgj    文件:KeySetReader.java   
/**
 * Loads a {@link KeySet} from an {@link java.io.InputStream}.
 */
public KeySet read(InputStream input) throws CryptographicException, IOException {
    try {
        final KeySet keySet = new KeySet(new PGPSecretKeyRing(input, new JcaKeyFingerprintCalculator()));
        final MasterKey masterKey = keySet.getMasterKey();
        final SubKey subKey = keySet.getSubKey();

        final KeySignature masterSig = masterKey.signature;
        if (masterSig == null || !masterSig.verifyCertification(masterKey)) {
            throw new CryptographicException("Key set has no self-signed master key");
        }

        final KeySignature subSig = subKey.signature;
        if (subSig == null || !subSig.verifyCertification(subKey, masterKey)) {
            throw new CryptographicException("Key set has no valid subkey");
        }

        return keySet;
    } catch (PGPException e) {
        throw new CryptographicException(e);
    } finally {
        input.close();
    }
}
项目:apt-repo    文件:PGPSigner.java   
/**
 * Returns the secret key matching the specified identifier.
 *
 * @param input the input stream containing the keyring collection
 * @param keyId the 4 bytes identifier of the key
 */
private PGPSecretKey getSecretKey(InputStream input, String keyId) throws IOException, PGPException {
    PGPSecretKeyRingCollection keyrings = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input), new JcaKeyFingerprintCalculator());

    Iterator rIt = keyrings.getKeyRings();

    while (rIt.hasNext()) {
        PGPSecretKeyRing kRing = (PGPSecretKeyRing) rIt.next();
        Iterator kIt = kRing.getSecretKeys();

        while (kIt.hasNext()) {
            PGPSecretKey key = (PGPSecretKey) kIt.next();

            if (key.isSigningKey() && String.format("%08x", key.getKeyID() & 0xFFFFFFFFL).equals(keyId.toLowerCase())) {
                return key;
            }
        }
    }

    return null;
}
项目:saveOrganizer    文件:KeyIO.java   
public static PGPSecretKey readSecretKey(InputStream in)
    throws IOException, PGPException
{
    in = PGPUtil.getDecoderStream(in);
    PGPSecretKeyRingCollection keyRingCollection = new PGPSecretKeyRingCollection(in, new JcaKeyFingerprintCalculator());

    //
    // We just loop through the collection till we find a key suitable for signing.
    // In the real world you would probably want to be a bit smarter about this.
    //
    PGPSecretKey secretKey = null;

    Iterator<PGPSecretKeyRing> rIt = keyRingCollection.getKeyRings();
    while (secretKey == null && rIt.hasNext()) {
        PGPSecretKeyRing keyRing = rIt.next();
        Iterator<PGPSecretKey> kIt = keyRing.getSecretKeys();
        while (secretKey == null && kIt.hasNext()) {
            PGPSecretKey key = kIt.next();
            if (key.isSigningKey()) {
                secretKey = key;
            }
        }
    }

    // Validate secret key
    if (secretKey == null) {
        throw new IllegalArgumentException("Can't find private key in the key ring.");
    }
    if (!secretKey.isSigningKey()) {
        throw new IllegalArgumentException("Private key does not allow signing.");
    }
    if (secretKey.getPublicKey().isRevoked()) {
        throw new IllegalArgumentException("Private key has been revoked.");
    }

    return secretKey;
}
项目:saveOrganizer    文件:PGPUtils.java   
/**
 * A simple routine that opens a key ring file and loads the first available
 * key suitable for encryption.
 * 
 * @param input
 *            data stream containing the public key data
 * @return the first public key found.
 * @throws IOException
 * @throws PGPException
 */
static PGPPublicKey readPublicKey(InputStream input) throws IOException, PGPException
{
    PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(input),
            new JcaKeyFingerprintCalculator());

    //
    // we just loop through the collection till we find a key suitable for
    // encryption, in the real
    // world you would probably want to be a bit smarter about this.
    //

    Iterator keyRingIter = pgpPub.getKeyRings();
    while (keyRingIter.hasNext())
    {
        PGPPublicKeyRing keyRing = (PGPPublicKeyRing) keyRingIter.next();

        Iterator keyIter = keyRing.getPublicKeys();
        while (keyIter.hasNext())
        {
            PGPPublicKey key = (PGPPublicKey) keyIter.next();

            if (key.isEncryptionKey())
            {
                return key;
            }
        }
    }

    throw new IllegalArgumentException("Can't find encryption key in key ring.");
}
项目:saveOrganizer    文件:PGPUtils.java   
/**
 * A simple routine that opens a key ring file and loads the first available
 * key suitable for signature generation.
 * 
 * @param input
 *            stream to read the secret key ring collection from.
 * @return a secret key.
 * @throws IOException
 *             on a problem with using the input stream.
 * @throws PGPException
 *             if there is an issue parsing the input stream.
 */
static PGPSecretKey readSecretKey(InputStream input) throws IOException, PGPException
{
    PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input),
            new JcaKeyFingerprintCalculator());

    //
    // we just loop through the collection till we find a key suitable for
    // encryption, in the real
    // world you would probably want to be a bit smarter about this.
    //

    Iterator keyRingIter = pgpSec.getKeyRings();
    while (keyRingIter.hasNext())
    {
        PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRingIter.next();

        Iterator keyIter = keyRing.getSecretKeys();
        while (keyIter.hasNext())
        {
            PGPSecretKey key = (PGPSecretKey) keyIter.next();

            if (key.isSigningKey())
            {
                return key;
            }
        }
    }

    throw new IllegalArgumentException("Can't find signing key in key ring.");
}
项目:pgp-encryption-using-java    文件:PGPEncryptionKeys.java   
/**
 * A simple routine that iterates through the keys in a key ring file
 * and selects the key, which can be used for encryption, based on a public key UserID if it exists.
 *
 * @param input data stream containing the public key data
 * @param publicKeyUserId UserID of the key to use for encryption
 * @return the first public key found.
 * @throws IOException
 * @throws PGPException
 */
private static PGPPublicKey readPublicKey(InputStream input, String publicKeyUserId) throws IOException, PGPException
{
    PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(
            PGPUtil.getDecoderStream(input), new JcaKeyFingerprintCalculator());

    Iterator keyRingIter = pgpPub.getKeyRings();
    while (keyRingIter.hasNext())
    {
        PGPPublicKeyRing keyRing = (PGPPublicKeyRing)keyRingIter.next();

        Iterator keyIter = keyRing.getPublicKeys();
        while (keyIter.hasNext())
        {
            PGPPublicKey key = (PGPPublicKey)keyIter.next();

            if (key.isEncryptionKey())
            {
                Iterator userIdIter = key.getUserIDs();
                while(userIdIter.hasNext()){
                    String userId = (String)userIdIter.next();
                    if (userId.equals(publicKeyUserId))
                        return key;
                }
            }
        }
    }

    throw new IllegalArgumentException("Can't find encryption key in key ring.");
}
项目:pgp-encryption-using-java    文件:PGPEncryptionKeys.java   
/**
 * A simple routine that opens a key ring file and loads the first available key
 * suitable for signature generation.
 *
 * @param input stream to read the secret key ring collection from.
 * @param secretKeyUserId UserID of the key to use for signing
 * @return a secret key.
 * @throws IOException on a problem with using the input stream.
 * @throws PGPException if there is an issue parsing the input stream.
 */
static PGPSecretKey readSecretKey(InputStream input, String secretKeyUserId) throws IOException, PGPException
{
    PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
            PGPUtil.getDecoderStream(input), new JcaKeyFingerprintCalculator());

    Iterator keyRingIter = pgpSec.getKeyRings();
    while (keyRingIter.hasNext())
    {
        PGPSecretKeyRing keyRing = (PGPSecretKeyRing)keyRingIter.next();

        Iterator keyIter = keyRing.getSecretKeys();
        while (keyIter.hasNext())
        {
            PGPSecretKey key = (PGPSecretKey)keyIter.next();

            if (key.isSigningKey())
            {
                Iterator userIdIter = key.getUserIDs();
                while(userIdIter.hasNext()){
                    String userId = (String)userIdIter.next();
                    if (userId.equals(secretKeyUserId))
                        return key;
                }
            }
        }
    }

    throw new IllegalArgumentException("Can't find signing key in key ring.");
}
项目:jfwknop    文件:GpgUtils.java   
static public void addPrivateKeyToKeyring(final String gpgHomeDirectory, final String keyringFile) throws FileNotFoundException, IOException, PGPException {
    Security.addProvider(new BouncyCastleProvider());

    // Read user secret keyring
    FileInputStream inPriv = new FileInputStream(gpgHomeDirectory + "/secring.gpg");
    PGPSecretKeyRingCollection privRings = new PGPSecretKeyRingCollection(inPriv, new JcaKeyFingerprintCalculator());

    // Read keys (public and private) from armored file
    PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
        PGPUtil.getDecoderStream(new FileInputStream(keyringFile)), new JcaKeyFingerprintCalculator());

    // Iterate over the keys
    Iterator keyRingIter = pgpSec.getKeyRings();
    while (keyRingIter.hasNext()) {
        PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRingIter.next();
        privRings = PGPSecretKeyRingCollection.addSecretKeyRing(privRings, keyRing);

        Iterator keyIter = keyRing.getSecretKeys();
        while (keyIter.hasNext()) {
            PGPSecretKey key = (PGPSecretKey) keyIter.next();

            if (key.isSigningKey()) {
                System.out.println("Private key imported " + Long.toHexString(key.getKeyID()).toUpperCase());
            }
        }
    }

    try (FileOutputStream out = new FileOutputStream(new File(gpgHomeDirectory + "/secring.gpg"))) {
        privRings.encode(out);
    }
}
项目:jfwknop    文件:GpgUtils.java   
static public void addPublicKeyToKeyring(String gpgHomeDirectory, String keyringFile) throws FileNotFoundException, IOException, PGPException {
    Security.addProvider(new BouncyCastleProvider());

    FileInputStream in = new FileInputStream(gpgHomeDirectory + "/pubring.gpg");
    PGPPublicKeyRingCollection pubRings = new PGPPublicKeyRingCollection(in, new JcaKeyFingerprintCalculator());

    PGPPublicKeyRing pgpKeyring = new PGPPublicKeyRing(PGPUtil.getDecoderStream(new FileInputStream(keyringFile)), new JcaKeyFingerprintCalculator());
    pubRings = PGPPublicKeyRingCollection.addPublicKeyRing(pubRings, pgpKeyring);

    try (FileOutputStream out = new FileOutputStream(new File(gpgHomeDirectory + "/pubring.gpg"))) {
        pubRings.encode(out);
    }
}
项目:base    文件:PGPEncryptionUtil.java   
/**
 * ***********************************************
 */
private static PGPLiteralData asLiteral( final InputStream clear ) throws IOException, PGPException
{
    final PGPObjectFactory plainFact = new PGPObjectFactory( clear, new JcaKeyFingerprintCalculator() );
    final Object message = plainFact.nextObject();
    if ( message instanceof PGPCompressedData )
    {
        final PGPCompressedData cData = ( PGPCompressedData ) message;
        final PGPObjectFactory pgpFact =
                new PGPObjectFactory( cData.getDataStream(), new JcaKeyFingerprintCalculator() );
        // Find the first PGPLiteralData object
        Object object = null;
        for ( int safety = 0; ( safety++ < 1000 ) && !( object instanceof PGPLiteralData );
              object = pgpFact.nextObject() )
        {
            //ignore
        }
        return ( PGPLiteralData ) object;
    }
    else if ( message instanceof PGPLiteralData )
    {
        return ( PGPLiteralData ) message;
    }
    else if ( message instanceof PGPOnePassSignatureList )
    {
        throw new PGPException( "encrypted message contains a signed message - not literal data." );
    }
    else
    {
        throw new PGPException(
                "message is not a simple encrypted file - type unknown: " + message.getClass().getName() );
    }
}
项目:base    文件:PGPEncryptionUtilTest.java   
private void signKeyAndPrintIds( KeyPair first, KeyPair second, String password ) throws IOException, PGPException
{
    InputStream firstPublicStream = new ByteArrayInputStream( first.getPubKeyring() );
    InputStream secondPublicStream = new ByteArrayInputStream( second.getPubKeyring() );
    InputStream secondSecretStream = new ByteArrayInputStream( second.getSecKeyring() );

    PGPPublicKeyRingCollection keyrings =
            new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( firstPublicStream ),
                    new JcaKeyFingerprintCalculator() );

    PGPPublicKeyRing firstPublicKeyRing = null;
    if ( keyrings.getKeyRings().hasNext() )
    {
        firstPublicKeyRing = keyrings.getKeyRings().next();


        PGPSecretKey secondSecretKey =
                PGPEncryptionUtil.findSecretKeyById( secondSecretStream, second.getPrimaryKeyId() );
        PGPPublicKey secondPublicKey =
                PGPEncryptionUtil.findPublicKeyById( secondPublicStream, second.getPrimaryKeyId() );

        if ( secondSecretKey != null )
        {
            String keyId = Long.toHexString( secondSecretKey.getKeyID() );

            PGPPublicKeyRing firstSignedPublicKeyRing =
                    PGPEncryptionUtil.signPublicKey( firstPublicKeyRing, keyId, secondSecretKey, password );

            printPublicKeySignatures( firstSignedPublicKeyRing.getPublicKey(), secondPublicKey );

            first.setPubKeyring( firstSignedPublicKeyRing.getEncoded() );
        }
    }
}
项目:base    文件:PGPEncryptionUtilTest.java   
@Test
public void testVerifyClearSign() throws Exception
{
    InputStream secondPublicStream = findFile( PLUGIN_PUBLIC_KEY );
    PGPPublicKeyRingCollection secondPublicKeyRingCollection =
            new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( secondPublicStream ),
                    new JcaKeyFingerprintCalculator() );

    PGPPublicKeyRing pgpKeyring = secondPublicKeyRingCollection
            .getPublicKeyRing( secondPublicKeyRingCollection.iterator().next().getPublicKey().getKeyID() );

    String signedMessage = IOUtils.toString( findFile( "signedMessage.txt" ) );

    logger.info( "\n" + signedMessage );

    boolean result = PGPEncryptionUtil.verifyClearSign( signedMessage.getBytes(), pgpKeyring );
    if ( result )
    {
        logger.info( "signature verified." );
    }
    else
    {
        logger.info( "signature verification failed." );
    }

    assertEquals( true, result );
}
项目:CryptMeme    文件:PGPSecretKeyRing.java   
/**
 * @deprecated use version that takes KeyFingerprintCalculator
 */
public PGPSecretKeyRing(
    InputStream    in)
    throws IOException, PGPException
{
    this(in, new JcaKeyFingerprintCalculator());
}
项目:CryptMeme    文件:PGPECDSATest.java   
public void performTest()
    throws Exception
{
    PGPUtil.setDefaultProvider("BC");

    //
    // Read the public key
    //
    PGPPublicKeyRing        pubKeyRing = new PGPPublicKeyRing(testPubKey, new JcaKeyFingerprintCalculator());

    for (Iterator it = pubKeyRing.getPublicKey().getSignatures(); it.hasNext();)
    {
        PGPSignature certification = (PGPSignature)it.next();

        certification.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"), pubKeyRing.getPublicKey());

        if (!certification.verifyCertification((String)pubKeyRing.getPublicKey().getUserIDs().next(), pubKeyRing.getPublicKey()))
        {
            fail("self certification does not verify");
        }
    }

    //
    // Read the private key
    //
    PGPSecretKeyRing        secretKeyRing = new PGPSecretKeyRing(testPrivKey, new JcaKeyFingerprintCalculator());


    generateAndSign();
}
项目:CryptMeme    文件:PGPPublicKeyRing.java   
/**
 * @deprecated use version that takes a KeyFingerPrintCalculator
 */
public PGPPublicKeyRing(
    byte[]    encoding)
    throws IOException
{
    this(new ByteArrayInputStream(encoding), new JcaKeyFingerprintCalculator());
}
项目:CryptMeme    文件:PGPPublicKeyRing.java   
/**
 * @deprecated use version that takes a KeyFingerPrintCalculator
 */
public PGPPublicKeyRing(
    InputStream    in)
    throws IOException
{
    this(in, new JcaKeyFingerprintCalculator());
}
项目:divconq    文件:EncryptedFileStream.java   
public void loadPublicKey(Path keyring) throws IOException, PGPException {
    // TODO move some of this to dcPGPUtil
       PGPPublicKey pubKey = null;

       InputStream keyIn = new BufferedInputStream(new FileInputStream(keyring.toFile()));

    PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(org.bouncycastle.openpgp.PGPUtil.getDecoderStream(keyIn), new JcaKeyFingerprintCalculator());

       //
       // we just loop through the collection till we find a key suitable for encryption, in the real
       // world you would probably want to be a bit smarter about this.
       //

       @SuppressWarnings("rawtypes")
    Iterator keyRingIter = pgpPub.getKeyRings();

       while (keyRingIter.hasNext() && (pubKey == null)) {
           PGPPublicKeyRing keyRing = (PGPPublicKeyRing)keyRingIter.next();

           @SuppressWarnings("rawtypes")
        Iterator keyIter = keyRing.getPublicKeys();

           while (keyIter.hasNext() && (pubKey == null)) {
               PGPPublicKey key = (PGPPublicKey)keyIter.next();

               if (key.isEncryptionKey())
                pubKey = key;
           }
       }

       if (pubKey == null)
        throw new IllegalArgumentException("Can't find encryption key in key ring.");

    this.methods.add(new JcePublicKeyKeyEncryptionMethodGenerator(pubKey));
}
项目:irma_future_id    文件:PGPSecretKeyRing.java   
/**
 * @deprecated use version that takes KeyFingerprintCalculator
 */
public PGPSecretKeyRing(
    InputStream    in)
    throws IOException, PGPException
{
    this(in, new JcaKeyFingerprintCalculator());
}
项目:irma_future_id    文件:PGPPublicKeyRing.java   
/**
 * @deprecated use version that takes a KeyFingerPrintCalculator
 */
public PGPPublicKeyRing(
    byte[]    encoding)
    throws IOException
{
    this(new ByteArrayInputStream(encoding), new JcaKeyFingerprintCalculator());
}
项目:irma_future_id    文件:PGPPublicKeyRing.java   
/**
 * @deprecated use version that takes a KeyFingerPrintCalculator
 */
public PGPPublicKeyRing(
    InputStream    in)
    throws IOException
{
    this(in, new JcaKeyFingerprintCalculator());
}
项目:irma_future_id    文件:PGPECDSATest.java   
public void performTest()
    throws Exception
{
    PGPUtil.setDefaultProvider("BC");

    //
    // Read the public key
    //
    PGPPublicKeyRing        pubKeyRing = new PGPPublicKeyRing(testPubKey, new JcaKeyFingerprintCalculator());

    for (Iterator it = pubKeyRing.getPublicKey().getSignatures(); it.hasNext();)
    {
        PGPSignature certification = (PGPSignature)it.next();

        certification.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"), pubKeyRing.getPublicKey());

        if (!certification.verifyCertification((String)pubKeyRing.getPublicKey().getUserIDs().next(), pubKeyRing.getPublicKey()))
        {
            fail("self certification does not verify");
        }
    }

    //
    // Read the private key
    //
    PGPSecretKeyRing        secretKeyRing = new PGPSecretKeyRing(testPrivKey, new JcaKeyFingerprintCalculator());


    generateAndSign();
}
项目:bc-java    文件:PGPSecretKeyRing.java   
/**
 * @deprecated use version that takes KeyFingerprintCalculator
 */
public PGPSecretKeyRing(
    InputStream    in)
    throws IOException, PGPException
{
    this(in, new JcaKeyFingerprintCalculator());
}
项目:bc-java    文件:PGPPublicKeyRing.java   
/**
 * @deprecated use version that takes a KeyFingerPrintCalculator
 */
public PGPPublicKeyRing(
    byte[]    encoding)
    throws IOException
{
    this(new ByteArrayInputStream(encoding), new JcaKeyFingerprintCalculator());
}
项目:bc-java    文件:PGPPublicKeyRing.java   
/**
 * @deprecated use version that takes a KeyFingerPrintCalculator
 */
public PGPPublicKeyRing(
    InputStream    in)
    throws IOException
{
    this(in, new JcaKeyFingerprintCalculator());
}
项目:bc-java    文件:PGPECDSATest.java   
public void performTest()
    throws Exception
{
    PGPUtil.setDefaultProvider("BC");

    //
    // Read the public key
    //
    PGPPublicKeyRing        pubKeyRing = new PGPPublicKeyRing(testPubKey, new JcaKeyFingerprintCalculator());

    for (Iterator it = pubKeyRing.getPublicKey().getSignatures(); it.hasNext();)
    {
        PGPSignature certification = (PGPSignature)it.next();

        certification.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"), pubKeyRing.getPublicKey());

        if (!certification.verifyCertification((String)pubKeyRing.getPublicKey().getUserIDs().next(), pubKeyRing.getPublicKey()))
        {
            fail("self certification does not verify");
        }
    }

    //
    // Read the private key
    //
    PGPSecretKeyRing        secretKeyRing = new PGPSecretKeyRing(testPrivKey, new JcaKeyFingerprintCalculator());


    generateAndSign();
}
项目:gpgj    文件:MasterKeyTest.java   
@Before
public void setUp() throws Exception {
    try (FileInputStream file = new FileInputStream("src/test/resources/secret-keyring.gpg")) {
        final PGPSecretKeyRing keyRing = new PGPSecretKeyRing(file, new JcaKeyFingerprintCalculator());
        this.key = new MasterKey(keyRing.getSecretKey(0x8C7035EF8838238CL));
    }
}