Skip to content

Instantly share code, notes, and snippets.

@stefan2904
Created September 8, 2014 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefan2904/e76625b0ab5eed5aa8c7 to your computer and use it in GitHub Desktop.
Save stefan2904/e76625b0ab5eed5aa8c7 to your computer and use it in GitHub Desktop.
JavaPrivacyGuard API v0.3 Demo
public class DecryptPGPMessage {
private static PGPMessage parseMessage(FileInputStream fis) throws Base64Exception, IOException, PGPException {
Base64CRC24InputStream in = new Base64CRC24InputStream(fis);
return new PGPMessage(in);
}
private static PGPPrivateKey parsePrivatekey(FileInputStream fis) throws Base64Exception, IOException, PGPException {
Base64CRC24InputStream in = new Base64CRC24InputStream(fis);
return new PGPPrivateKey(in);
}
public static void main(String[] args) throws Exception {
IAIK.addAsProvider();
FileInputStream fis1 = new FileInputStream("demo/dsa.test.pgp");
PGPMessage pgpmessage = parseMessage(fis1);
FileInputStream fis2 = new FileInputStream("demo/dsa.privkey.pgp");
PGPPrivateKey privkey = parsePrivatekey(fis2);
pgpmessage.setDecryptionKey(privkey);
PGPData data = pgpmessage.doDecrypt();
System.out.println(new String(ByteStreamHelper.inputStreamToByteArray(data.getDataStream())));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment