Created
April 7, 2012 05:08
-
-
Save yamanyar/2325430 to your computer and use it in GitHub Desktop.
encrypt in java
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
protected String encrypt(String token) throws Exception { | |
// Instantiate the cipher | |
final SecretKeySpec key = new SecretKeySpec("oldhouse".getBytes("ISO-8859-1"), "DES"); | |
AlgorithmParameterSpec paramSpec = new IvParameterSpec("houseold".getBytes()); | |
Cipher cipher = Cipher.getInstance("DES/CFB8/NoPadding"); | |
cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec); | |
byte[] binaryData = cipher.doFinal(token.getBytes("ISO-8859-1")); | |
return new String(org.apache.commons.codec.binary.Base64.encodeBase64(binaryData), "ISO-8859-1"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment