in , , ,

Updating MD5 Tool To use SHA 256/512 Hash

Back in the previous post on making a tool to find MD5 hash values… we were limited to just MD5 hash types.  To add more support for testing, I added support for more hash types (SHA-256 and SHA-512), by doing the following:

Controllers

The functions in the AddToDictionaryController:

    def submitToDictionary(){
        def newWord = params.newWord
        def digest = MessageDigest.getInstance("MD5")
        def md5hash = new BigInteger(1,digest.digest(newWord.getBytes())).toString(16).padLeft(32,"0")
 
        def sha256 = MessageDigest.getInstance("SHA-256")
        def sha256Hash = new BigInteger(1,sha256.digest(newWord.getBytes())).toString(16).padLeft(64,"0")
        def sha512 = MessageDigest.getInstance("SHA-512")
        def sha512Hash = new BigInteger(1,sha512.digest(newWord.getBytes())).toString(16).padLeft(128,"0")
        Dictionary dictionary = new Dictionary()
        dictionary.md5 = md5hash
        dictionary.word = newWord
        dictionary.sha256 = sha256Hash
        dictionary.sha512 = sha512Hash
        dictionary.save()
    }
    def fileToDictionary(){
        request.getFile('fileUpload').inputStream.splitEachLine('\n') { word ->
                println word[0]
 
                def digest = MessageDigest.getInstance("MD5")
                def md5hash = new BigInteger(1,digest.digest(word[0].getBytes())).toString(16).padLeft(32,"0")
 
                def sha256 = MessageDigest.getInstance("SHA-256")
                def sha256Hash = new BigInteger(1,sha256.digest(word[0].getBytes())).toString(16).padLeft(64,"0")
                def sha512 = MessageDigest.getInstance("SHA-512")
                def sha512Hash = new BigInteger(1,sha512.digest(word[0].getBytes())).toString(16).padLeft(128,"0")
 
                Dictionary dictionary = new Dictionary()
                dictionary.md5 = md5hash
                dictionary.word = word[0]
                dictionary.sha256 = sha256Hash
                dictionary.sha512 = sha512Hash
                dictionary.save()
        }
    }

Views

MD5:<br>
<g:form controller=”hashLookup” action=”lookupMd5Hash”>
<g:textField name=”submittedHash” value=”${submittedHash}” id=”submittedHash”/>
<g:submitButton name=”submit”/>
</g:form>
SHA-256<br>
<g:form controller=”hashLookup” action=”lookupSha256″>
<g:textField name=”submittedHash” value=”${submittedHash}” id=”submittedHash”/>
<g:submitButton name=”submit”/>
</g:form>
SHA-512:<br>
<g:form controller=”hashLookup” action=”lookupSha512″>
<g:textField name=”submittedHash” value=”${submittedHash}” id=”submittedHash”/>
<g:submitButton name=”submit”/>
</g:form>

We need to make gsp’s for each function… so a lookupMd5Hash.gsp, lookupSha512.gsp, lookupSha256.gsp.  Each gsp needs a statement like this:

<%
nutcracker.Dictionary dictionary = new nutcracker.Dictionary()
def md5HashResult = dictionary.executeQuery(“select word from Dictionary where md5=’${params.submittedHash}'”)[0]
%>
The plain text word for your hash is: ${md5HashResult}

Then in the lookupSha256.gsp page you change the query to look for “where sha256…” and so forth…

Now you can encrypt your dictionaries to multiple formats on upload, and then perform lookups on all the results.

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Written by Admin

I work for a Telecom company writing and testing software. My passion for writing code is expressed through this blog. It's my hope that it gives hope to any and all who are self-taught.

Comments

One Ping

  1. Pingback:

Leave a Reply

Loading…

Tool: MD5 dictionary seed and MD5 Hash Lookup

Building a Port Scanner in Groovy, Python & Ruby