protected PGPPrivateKey findPrivateKey ( PGPSecretKey pgpSecretKey , String password ) throws PGPException { LOGGER . trace ( "findPrivateKey(PGPSecretKey, String)" ) ; LOGGER . trace ( "Secret Key: {}, Password: {}" , pgpSecretKey == null ? "not set" : "set" , password == null ? "not set" : "********" ) ; PGPPrivateKey result = null ; PBESecretKeyDecryptor pbeSecretKeyDecryptor = new BcPBESecretKeyDecryptorBuilder ( new BcPGPDigestCalculatorProvider ( ) ) . build ( password . toCharArray ( ) ) ; LOGGER . info ( "Extracting private key" ) ; result = pgpSecretKey . extractPrivateKey ( pbeSecretKeyDecryptor ) ; if ( result == null && LOGGER . isErrorEnabled ( ) ) { LOGGER . error ( "No private key could be extracted" ) ; } return result ; }
read the private key from the given secret key