PGPKeyHelper { public static PGPPrivateKey readPrivateKey( InputStream is, String password ) throws PGPException, IOException { PGPSecretKey secretKey = readSecretKey( is ); return secretKey.extractPrivateKey( new JcePBESecretKeyDecryptorBuilder().setProvider( "BC" ).build( password.toCharArray() ) ); } private  PGPKeyHelper(); static PGPPublicKey readPublicKey( InputStream is ); static PGPPublicKey readPublicKey( String filePath ); static PGPPublicKey readPublicKeyFromString( String key ); static PGPPrivateKey readPrivateKey( InputStream is, String password ); static PGPPrivateKey readPrivateKey( String filePath, String password ); static String getFingerprint( PGPPublicKey publicKey ); static String getOwnerString( PGPPublicKey publicKey );  }
@Test public void testGetPrivateKeyFromStream() throws IOException, PGPException { try ( InputStream is = new FileInputStream( PGPTestDataFactory.PRIVATE_KEY_PATH ) ) { PGPPrivateKey privateKey = PGPKeyHelper.readPrivateKey( is, PGPTestDataFactory.DEFAULT_PASSWORD ); assertNotNull( privateKey ); } }
@Test public void testGetPrivateKeyFromPath() throws IOException, PGPException { PGPPrivateKey privateKey = PGPKeyHelper.readPrivateKey( PGPTestDataFactory.PRIVATE_KEY_PATH, PGPTestDataFactory.DEFAULT_PASSWORD ); assertNotNull( privateKey ); }