MD4 and DES for unicode strings (samba passwd file manipulation)

Fredrik Lundh fredrik at pythonware.com
Wed Sep 4 09:14:12 CEST 2002


Arcady Genkin wrote:

> And yet I can't create the right crypted strings:
>
>   >>> from Crypto.Hash import MD4
>   >>>
>   >>> m = MD4.new()
>   >>> m.update( u'111222333' )
>   >>> m.hexdigest().upper()
>   'A672E5EDFDAD90A15228E0AEC2AA9161'
>   >>> # SAMBA-encoded password "111222333":
>   >>> samba
>   'B66B458E27BD714F99A05EE3C479FBF1'
>
> Perhaps the problem lies with Unicode encoding?  Samba's man page (see
> the link below) says that the string is obtained by taking MD4 hash on
> the password, represented as a string of 16-bit little-endian unicode
> characters.

if you want a string of 16-bit little-endian unicode characters,
make sure you have one:

    m = MD4.new()
    m.update(password.encode("utf-16-le"))
    m.hexdigest().upper()

(I don't have the MD4 library, so I cannot verify this.  But if
it works, it works for both 8-bit strings with ASCII text, and
Unicode strings)

</F>





More information about the Python-list mailing list