Created
October 24, 2017 14:46
-
-
Save prabhatkashyap/60d94ee8fc66acb9217064f3defa303d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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