Skip to content

Instantly share code, notes, and snippets.

@idesaku
Created March 31, 2009 06:31
Show Gist options
  • Save idesaku/88087 to your computer and use it in GitHub Desktop.
Save idesaku/88087 to your computer and use it in GitHub Desktop.
Hex digest generator.
#!/usr/bin/env groovy
import java.security.MessageDigest
if(args.length < 1) {
System.err.println("usage: digest.groovy string [type]")
return
}
def src = args[0]
def type = "SHA1"
if(args.length >= 2) {
type = args[1]
}
def md = MessageDigest.getInstance(type)
md.update(src.getBytes())
println md.digest().collect { String.format("%02x", it) }.inject("") { str, item -> str + item }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment