code: 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);
      }
docs: Extracts the PGP private key from an encoded stream.
  @param keyStream stream providing the encoded private key
  @param keyId id of the secret key to extract
  @param password passphrase for the secret key
  @return the private key object
  @throws IOException if there is an error reading from the stream
  @throws PGPException if the secret key cannot be extracted