md5.hexdigest() converting unicode string to ascii

From: uebertester (mgibson_at_tripwire.com)
Date: 04/16/04


Date: 15 Apr 2004 15:50:00 -0700

I'm trying to get a MD5 hash of a registry key value on Windows 2000
Server. The registry value is a string which is stored as a unicode
string. I can get the registry key value and pass it to md5 via
update(), however, hexdigest() returns a hash value for the ascii
equivalent of the unicode string. Not the hash of the unicode string
itself. I've verified this by creating a text file containing an
ascii form of the string and one containing a unicode form of the
string. The hash returned by md5.hexdigest() matches that when I run
md5sum on the ascii file.

Here is the code I'm using:

import _winreg
from md5 import md5

x=_winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
y= _winreg.OpenKey(x,
r"SOFTWARE\Microsoft\Windows\CurrentVersion\URL\DefaultPrefix")

sValue = _winreg.QueryValueEx(y,"")
print sValue

m = md5()
m.update(unicode(sValue[0]))
MD5 = m.hexdigest()

print "%s \n%d" % (sValue[0], sValue[1])
print MD5

_winreg.CloseKey(y)
_winreg.CloseKey(x)

Any help would be appreciated.



Relevant Pages

  • Re: long index strings
    ... I'm sure breaking a long string into 20 byte segments would work, ... What I was hoping for was a way to compute a mathematical hash such ... as MD5 in Filemaker. ... What are the requirements for writing a plug-in of your own? ...
    (comp.databases.filemaker)
  • Re: "Collision for Hash Functions MD4, MD5, HAVAL-128 and RIPEMD"
    ... this was the Year of Doom for cryptographic hash functions. ... These go into great detail on the SHA-0 and MD5 collisions ... Difficulty in the former is called "collision resistance", ... you probably meant to say was "I can find a *different* string whose ...
    (comp.os.linux.security)
  • Repairing damaged MD5 values
    ... The result is that whenever the MD5 hashed bytes contained a byte ... it was stored as one hex digit instead of two. ... So instead of uniform string lengths of 32, ... in a 26 digit hash than in a 32 digit. ...
    (microsoft.public.sqlserver.programming)
  • RE: Need C# coding for MD5 Algorithm
    ... implementations of the MD5 hash algorithm inherit using C# ... // a 32 character hexadecimal string. ... // The MD5 hash of Hello World! ... Need C# coding for MD5 Algorithm ...
    (microsoft.public.dotnet.general)
  • Re: How to write a diff in VB6 for comparing two xml files?
    ... No, the best you could do is to read both into string and use StrCompbut it's inefficient and, but using the hash ... Private Declare Function CryptAcquireContext Lib "AdvAPI32.dll" Alias _ ... Dim HashAAs Byte, HashLenA As Long ...
    (microsoft.public.vb.general.discussion)