Skip to content

Instantly share code, notes, and snippets.

@prabhatkashyap
Created October 24, 2017 14:46
Show Gist options
  • Select an option

  • Save prabhatkashyap/60d94ee8fc66acb9217064f3defa303d to your computer and use it in GitHub Desktop.

Select an option

Save prabhatkashyap/60d94ee8fc66acb9217064f3defa303d to your computer and use it in GitHub Desktop.
static public String decrypt(String encryptedString) {
String UNICODE_FORMAT = "UTF8"
String DESEDE_ENCRYPTION_SCHEME = "DESede"
String myEncryptionKey = "Provide the same key used for encryption"
String myEncryptionScheme = DESEDE_ENCRYPTION_SCHEME
byte[] arrayBytes = myEncryptionKey.getBytes(UNICODE_FORMAT)
KeySpec ks = new DESedeKeySpec(arrayBytes)
SecretKeyFactory skf = SecretKeyFactory.getInstance(myEncryptionScheme)
Cipher cipher = Cipher.getInstance(myEncryptionScheme)
SecretKey key = skf.generateSecret(ks)
String decryptedText = null;
try {
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] encryptedText = Base64.decodeBase64(encryptedString);
byte[] plainText = cipher.doFinal(encryptedText);
decryptedText = new String(plainText);
} catch (Exception e) {
e.printStackTrace();
}
return decryptedText;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment