I need to create two simple methods for string DES encryption/decruption. The goal is to have these two methods in the following form
public static String desEcnrypt(String key, String clearMessage) { ..... }
public static String desDecrypt(String key, String encryptedMessage) { ..... }
I haven't found yet any example in this form.
Use the "not-yet-commons-ssl.jar" from http://juliusdavies.ca/commons-ssl/.
http://juliusdavies.ca/commons-ssl/pbe.html
PBE code example (DES-3):*
char[] password = {'c','h','a','n','g','e','i','t'};
byte[] data = "Hello World!".getBytes();
// Encrypt!
byte[] encrypted = OpenSSL.encrypt("des3", password, data);
System.out.println("ENCRYPTED: [" + new String(encrypted) + "]");
// Decrypt results of previous!
data = OpenSSL.decrypt("des3", password, encrypted);
System.out.println("DECRYPTED: [" + new String(data) + "]");
OUTPUT:
=======================
ENCRYPTED: [U2FsdGVkX19qplb9qVDVVEYxH8wjJDGpMS+F4/2pS2c=]
DECRYPTED: [Hello World!]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With