Skip to content

Instantly share code, notes, and snippets.

@yamanyar
Created April 7, 2012 05:08
Show Gist options
  • Save yamanyar/2325430 to your computer and use it in GitHub Desktop.
Save yamanyar/2325430 to your computer and use it in GitHub Desktop.
encrypt in java
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