Created
July 11, 2016 20:02
-
-
Save ahmedengu/ea9dd8b918578f6b05571601cbf33b0d 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
import javax.crypto.Cipher; | |
import javax.crypto.KeyGenerator; | |
import javax.crypto.SecretKey; | |
class DesEncrypter { | |
Cipher ecipher, dcipher; | |
DesEncrypter(SecretKey key) throws Exception { | |
ecipher = Cipher.getInstance("DES"); | |
dcipher = Cipher.getInstance("DES"); | |
ecipher.init(Cipher.ENCRYPT_MODE, key); | |
dcipher.init(Cipher.DECRYPT_MODE, key); | |
} | |
} | |
public class Main { | |
public static void main(String[] argv) throws Exception { | |
DesEncrypter encrypter = new DesEncrypter(KeyGenerator.getInstance("DES").generateKey()); | |
System.out.println(new sun.misc.BASE64Encoder().encode(encrypter.ecipher.doFinal("secret".getBytes("UTF8")))); | |
byte[] utf8 = encrypter.dcipher.doFinal(new sun.misc.BASE64Decoder().decodeBuffer(new sun.misc.BASE64Encoder().encode(encrypter.ecipher.doFinal("secret".getBytes("UTF8"))))); | |
System.out.println(new String(utf8, "UTF8")); | |
} | |
} |
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
1k2SZ1ltr2k= | |
secret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment