haicenhacks / DahuaHashCreator

Generates Dahua hashes, commonly found in security cam DVR units
24 stars 6 forks source link

how to parse unicode characters #4

Open carlesreig opened 3 years ago

carlesreig commented 3 years ago

When I try to encode this character "ú" (latin) it returns an error about encoding;

File "DahuaHash.py", line 45, in dhash m.update(passw.encode("ascii")) UnicodeEncodeError: 'ascii' codec can't encode character '\xfa' in position 0: ordinal not in range(128)

Is there some way to pass non ascii code to generate it's hash with this script?

haicenhacks commented 3 years ago

This was addressed in https://github.com/haicenhacks/DahuaHashCreator/issues/3#issuecomment-694595256

You need to modify the script to accept the encoding used, so change

dhash m.update(passw.encode("ascii")) to

dhash m.update(passw.encode("iso-8859-1"))

It might work with utf-8, but i'm not sure how the multibyte encoding would affect the hashing algorithm. I assume that once it goes through the md5 hash, that it wouldn't affect anything else, but I haven't tested that. I have not made this a permanent change because it seems to be system specific.