Skip to content

Instantly share code, notes, and snippets.

@lyhcode
Created September 5, 2012 14:04
Show Gist options
  • Save lyhcode/3637109 to your computer and use it in GitHub Desktop.
Save lyhcode/3637109 to your computer and use it in GitHub Desktop.
Groovy + DES Encryption
import java.security.*
import javax.crypto.*
import javax.crypto.spec.*
def source = new File('input.dat').text
def cipher = Cipher.getInstance('DES')
cipher.init(Cipher.ENCRYPT_MODE, SecretKeyFactory.getInstance('DES').generateSecret(new DESKeySpec('secret12'.getBytes('UTF-8'))))
def target = cipher.doFinal(source.bytes).encodeBase64()
new File('output.dat').write('${target}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment