Groovy web console

subscribe to the feed Subscribe
to this
site
Generate MD5 Hash (via #groovywebconsole)
tweet this snippet Tweet
this
script

Generate MD5 Hash

Published 7 months ago by Anonymous with tags MD5 hash
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import java.nio.charset.Charset
import java.security.MessageDigest

String s = "test";
   
MessageDigest md = MessageDigest.getInstance("MD5")
byte[] array = md.digest(s.getBytes(Charset.forName("UTF-8")))
String result = ""
for (final byte element : array) {
    result += Integer.toHexString(element & 0xFF | 0x100).substring(1, 3)
}

println result.toString()