Skip to content

Instantly share code, notes, and snippets.

@DoaJCBlogger
Created August 2, 2018 20:30
public static void main(String[] args) throws Exception{
Security.addProvider(new BouncyCastleProvider());
byte[] str = "OneDirection".getBytes();
ByteArrayInputStream bIn = new ByteArrayInputStream(str);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
JMemPGP.encryptBytes(bOut,bIn,str.length,"C:\\pub.gpg",true,true);
byte[] output = bOut.toByteArray();
bOut.close();
bIn.close();
System.out.println("Message:\n\n"+(new String(output))+"\n");
ByteArrayInputStream input2 = new ByteArrayInputStream(output);
bOut = new ByteArrayOutputStream();
JMemPGP.decryptBytes(input2,"C:\\sec.gpg","test".toCharArray(),bOut);
byte[] output2 = bOut.toByteArray();
String decryptedString = new String(output2);
System.out.println("Decrypted Message: \""+decryptedString+"\"");
System.out.println("Decrypted message length in bytes: "+decryptedString.length());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment