Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with MD5 Script

Status
Not open for further replies.

mefanning

MIS
Apr 26, 2010
19
US
I'm working on this function, but the output is always an incorrect hash. Any ideas?

Thanks.

Function SHA1(s)
Dim asc, enc, bytes, outstr, pos
Set asc = CreateObject("System.Text.UTF8Encoding")
Set enc = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
bytes = asc.GetBytes_4(s)
bytes = enc.ComputeHash_2((bytes))
outstr = ""

For pos = 1 To Lenb(bytes)
outstr = outstr & LCase(Right("0" & Hex(Ascb(Midb(bytes, pos, 1))), 2))
Next
SHA1 = outstr
wscript.echo SHA1
Set asc = Nothing
Set enc = Nothing


End Function
 
Just fixed the service provider to use SHA1...I've tried the different hash service providers and the output is never correct when I compare using a tool like HashCalc to calculate the SHA1 or MD5 hash.


Function SHA1(s)
Dim asc, enc, bytes, outstr, pos
Set asc = CreateObject("System.Text.UTF8Encoding")
Set enc = CreateObject("System.Security.Cryptography.SHA1CryptoServiceProvider")
bytes = asc.GetBytes_4(s)
bytes = enc.ComputeHash_2((bytes))
outstr = ""

For pos = 1 To Lenb(bytes)
outstr = outstr & LCase(Right("0" & Hex(Ascb(Midb(bytes, pos, 1))), 2))
Next
SHA1 = outstr
wscript.echo SHA1
Set asc = Nothing
Set enc = Nothing


End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top