protected static PGPPrivateKey findSecretKey ( InputStream keyStream , long keyId , char [ ] password ) throws Exception { PGPSecretKeyRingCollection keyRings = new PGPSecretKeyRingCollection ( PGPUtil . getDecoderStream ( keyStream ) , new BcKeyFingerprintCalculator ( ) ) ; PGPSecretKey secretKey = keyRings . getSecretKey ( keyId ) ; if ( secretKey == null ) { return null ; } PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder ( new JcaPGPDigestCalculatorProviderBuilder ( ) . setProvider ( PROVIDER ) . build ( ) ) . setProvider ( PROVIDER ) . build ( password ) ; return secretKey . extractPrivateKey ( decryptor ) ; }
Extracts the PGP private key from an encoded stream .