"); //-->
一个例子:将十六进制字符串写入二进制文件。
import struct t= "308201b83082015ea00302010202090093741f63c0d348c2300a06082a8648ce3d040302301d311b301906035504030c124d4f434b2d4341522d524f4f542d43412d45301e170d3231303531383032353134335a170d3236303531373032353134335a30263124302206035504030c1b446576696365204f454d20526f6f742043657274696669636174653059301306072a8648ce3d020106082a8648ce3d030107034200049076ead5ced3dc6b82c17ee0aa23d9a80b7adcee968ae0841db5c01aa092d1447aadcbcfa2dbe60607690e5abe2c84a55f730a1d01e67a9ede4f2edcd3879707a37e307c301d0603551d0e041604140b3f8afa130735b3641bb81d3129ffba74454453301f0603551d230418301680144f7e2ff298a4860254dd2e0fe59a2c89d5928eb230120603551d130101ff040830060101ff020101300e0603551d0f0101ff0404030202043016060a2b0601040182c46905020101ff04053003020101300a06082a8648ce3d0403020348003045022068a0d7fdd996f1a91f1ccc4d7b00bb6ed4d9bc68556253532c377b18e2da95aa022100ab6833c1a5f6618e4e3bc82a39f1908c897c92726d9ee353988f5b1f24bebf1c" #写二进制文件 strY = '' i = 0 with open("./x509.der","wb") as f: for x in t: strY += x i+=1 if (i%2 == 0): xHex = int(strY, 16) xHex = struct.pack("B",xHex) f.write(xHex) strY = '' print("done")
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。