Last active
November 8, 2019 18:10
-
-
Save b8x/941b4ead04f01473d1773bcc9a9e7100 to your computer and use it in GitHub Desktop.
DesCryptor - 3 Des Encryption & Decryption Java
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
import Decoder.BASE64Encoder; | |
import javax.crypto.Cipher; | |
import javax.crypto.SecretKey; | |
import javax.crypto.spec.SecretKeySpec; | |
public class DesCryptor { | |
// des encryption key | |
private static byte[] keyBytes = new byte[]{ | |
0x30, 0x48, 0x65, 0x64, 0x6d, 0x40, 0x40, 0x40, 0x60, 0x62, 0x62, 0x73, 0x45, 0x45, 0x65, 0x74, | |
0x82, 0x81, 0x71, 0x70, 0x67, 0x68, 0x4b, 0x65 | |
}; | |
// des encryption | |
public static String encrypt(String plainTextBytes) { | |
try { | |
final SecretKey key = new SecretKeySpec(keyBytes, "DESede"); | |
final Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding", "BC"); | |
cipher.init(Cipher.ENCRYPT_MODE, key); | |
return new BASE64Encoder().encode(cipher.doFinal(plainTextBytes.getBytes())); | |
} catch (Exception ex) { | |
ex.printStackTrace(); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment