Created
October 24, 2017 14:45
-
-
Save prabhatkashyap/cc53879c53069701f704ec31c9c89e97 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 encrypt(String unencryptedString) { | |
| String UNICODE_FORMAT = "UTF8" | |
| String DESEDE_ENCRYPTION_SCHEME = "DESede" | |
| String myEncryptionKey = "Provide your encryption key" | |
| 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 encryptedString = null; | |
| try { | |
| cipher.init(Cipher.ENCRYPT_MODE, key); | |
| byte[] plainText = unencryptedString.getBytes(UNICODE_FORMAT); | |
| byte[] encryptedText = cipher.doFinal(plainText); | |
| encryptedString = new String(Base64.encodeBase64(encryptedText)); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| return encryptedString; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment