我们试图匹配使用Python通过Oracle MD5哈希算法的哈希。根据他们的forums一切都在AL21UTF8散列之前编码:如何使用Python对AL32UTF8中的文本进行编码
-- Prior to encryption, hashing or keyed hashing, CLOB datatype is
-- converted to AL32UTF8. This allows cryptographic data to be
-- transferred and understood between databases with different
-- character sets, across character set changes and between
-- separate processes (for example, Java programs).
--
我开始还以为是UTF-8是不够好,但如果我这样做,我的哈希值仍然不匹配。因此,在额外挖掘之后,我发现这个article,其中规定从Oracle's Database Companion CD installation Guide:
AL32UTF8是适用于XMLType数据的Oracle数据库字符集。它相当于IANA注册的标准UTF-8编码,它支持所有有效的XML字符。
不要将Oracle数据库数据库字符集UTF8(无连字符)与数据库字符集AL32UTF8或字符编码UTF-8混淆。数据库字符集UTF8已被AL32UTF8取代。不要对XML数据使用UTF8。 UTF8仅支持Unicode版本3.1及更早版本;它不支持所有有效的XML字符。 AL32UTF8没有这样的限制。
所以我不能使用UTF-8,我无法弄清楚如何让Python的编解码器模块区分utf-8和utf8。如果我尝试AL32UTF8,它会引发错误。有没有其他人在Python中使用AL32UTF8进行编码?
我的编解码器的代码如下所示:
import codecs
sourceFmt = "ascii"
targetFmt = "utf8"
utfFile = "kesa_utf8.dat"
with codecs.open(old, "rU", sourceFmt) as sourceFile:
with codecs.open(utfFile, "w", targetFmt) as targetFile:
targetFile.write(sourceFile.read())
文件本身看起来像这样:
WC000|IC |KESA |KESA | | | |2012-07-31-15.12.36 |0090| | |\c\n
WC001|100534 |W.47212-0100534 |2012-07-31-15.12.36 | 00000000001270.00|USD|\c\n
WC002|100534 |W.47212-0100534 |Sally |H |Klass |1235 14th St. W. || |Palma Sola ||FL |USA |34209 | | | | | | | | |9412587545 | | |O | | ||20800426|645858741 |SSN | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | || | | | || | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |KESAPC | | | | | |N| | | || | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |\c\n
WC999|1000000000|1000000000|4000000000|
哈希应该是86D993FA7121E3B9EE1657A23345FE21
反正我哈希使用hashlib它:
import hashlib
with open(path) as f:
data = f.read()
mdhash = hashlib.md5(data)
mdhash = mdhash.hexdigest()
print mdhash
其结果是8421877dd9cdf7235eec47765821998c
您可以使用Oracle中的['convert'](http://www.techonthenet.com/oracle/functions/convert.php)函数来编码UTF-8中的AL32UTF8字符吗? – Ben 2012-08-01 13:46:32
我想你错过了文章。 UTF8有点奇怪,但与您的问题无关。 Oracle的AL32UTF8就是其他地方所谓的UTF-8。请显示您的代码并显示一个示例。 – Codo 2012-08-01 14:01:45
ASCII和UTF-8中的相同字符之间没有区别,即byte-for-byte。 – 2012-08-01 15:04:42