public static PGPPublicKey getPublicKey ( InputStream content ) throws Exception { InputStream in = PGPUtil . getDecoderStream ( content ) ; PGPPublicKeyRingCollection keyRingCollection = new PGPPublicKeyRingCollection ( in , new BcKeyFingerprintCalculator ( ) ) ; PGPPublicKey key = null ; Iterator < PGPPublicKeyRing > keyRings = keyRingCollection . getKeyRings ( ) ; while ( key == null && keyRings . hasNext ( ) ) { PGPPublicKeyRing keyRing = keyRings . next ( ) ; Iterator < PGPPublicKey > keys = keyRing . getPublicKeys ( ) ; while ( key == null && keys . hasNext ( ) ) { PGPPublicKey current = keys . next ( ) ; if ( current . isEncryptionKey ( ) ) { key = current ; } } } return key ; }
Extracts the PGP public key from an encoded stream .