Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python对AL32UTF8中的文本进行编码_Python_Oracle - Fatal编程技术网

如何使用Python对AL32UTF8中的文本进行编码

如何使用Python对AL32UTF8中的文本进行编码,python,oracle,Python,Oracle,我们正在尝试使用Python匹配经过Oracle MD5哈希算法处理的哈希。根据他们的说法,在散列之前,所有内容都以AL21UTF8编码: -- Prior to encryption, hashing or keyed hashing, CLOB datatype is -- converted to AL32UTF8. This allows cryptographic data to be -- transferred and understood between databases wi

我们正在尝试使用Python匹配经过Oracle MD5哈希算法处理的哈希。根据他们的说法,在散列之前,所有内容都以AL21UTF8编码:

-- 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已经足够好了,但如果我这样做,我的哈希值仍然不匹配。因此,在进一步挖掘之后,我发现了以下内容:

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|
文件本身如下所示:

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

结果是,无论客户机在做什么,都会导致数据本身发生更改,从而使其具有“\c\n”行结尾,并且在散列后,还会通过填充(末尾的空格)使文件中的行大小相同。一旦我们让客户端停止向我们提供坏数据,我们就能够复制散列。谢谢你的帮助

你能用Oracle中的函数在UTF-8中编码AL32UTF8字符吗?我猜你误解了这篇文章。UTF8有点奇怪,但与您的问题无关。Oracle的AL32UTF8在其他地方被称为UTF-8。请显示您的代码并显示一个示例。ASCII和UTF-8中的相同字符之间没有字节对字节的差异。@Ben-我们自己没有oracle。它来自一个使用oracle的客户机。Codo-I添加了代码和示例