Created
August 2, 2018 20:30
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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