Groovy web console

subscribe to the feed Subscribe
to this
site

Password Digest

Published 4 weeks ago by Patricio Ascencio with tags cryptography
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
def buildCreatedDateTime(){
    dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ")
    return dateFormat.format(new java.util.Date());
}

def buildNonce(){
    uuid = java.util.UUID.randomUUID().toString()
}

def generatePasswordDigest(nonce,created,password){
    md = java.security.MessageDigest.getInstance("SHA-1");
    input = "${nonce}${created}${password}"
    messageDigest = md.digest(input.getBytes())
    return messageDigest

}

def generateBase64(passwordDigest){
    encoder = java.util.Base64.getEncoder()
    encodedBytes = encoder.encode(passwordDigest)
    return new String(encodedBytes)
}

nonce = buildNonce()
created = buildCreatedDateTime()
password = "DB65207D00F47465E35A565537CC0C04"

println(created)
println(nonce)
println(password)

passwordDigest = generatePasswordDigest(nonce,created,password)
println(passwordDigest)

passwordDigestEncoded = generateBase64(passwordDigest)

println(passwordDigestEncoded)