Message3869
When using pythons md5 library to create a hex digest of a string
containing non-latin characters, an incorrect hash is returned. The
following code shows the difference:
# encoding: uft-8
from java.math import BigInteger
from java.security import MessageDigest
from java.security import NoSuchAlgorithmException
from java.lang import String
import md5
a = u"Gráin amháiñ ©ðƒ©óíßðƒóíıßðƒ‚íó©ı"
#a = "A lovely string to encrypt!"
b = String(a)
digest = MessageDigest.getInstance("MD5")
bytes = b.getBytes()
digest.reset()
java_hash = BigInteger(1, digest.digest(bytes)).toString(16)
print "Hash using Java:\t", java_hash
print "Hash in Python:\t\t", md5.new(a).hexdigest() |
|
Date |
User |
Action |
Args |
2008-12-03 15:54:39 | noelob | set | recipients:
+ noelob |
2008-12-03 15:54:39 | noelob | set | messageid: <1228319679.37.0.0593723220729.issue1189@psf.upfronthosting.co.za> |
2008-12-03 15:54:39 | noelob | link | issue1189 messages |
2008-12-03 15:54:38 | noelob | create | |
|