@
Crossin 同,我也觉得是编码的问题,不过我觉得直接用 bytes 来得更直接点…
@
chendajun 改成下面的就可以运行了,你可以试下
1 import binascii
2 from Crypto.Cipher.DES3 import DES3Cipher
3 from Crypto.Cipher import blockalgo
4
5
6 def _decode_ossauth(access_id, access_key, secret_key):
7 #bytedes_key = ""
8 #for b in secret_key:
9 #bytedes_key += "%c" % b
10 bytedes_key = bytes(secret_key)
11 print((type(bytedes_key), len(bytedes_key)))
12 byte_id = binascii.a2b_hex(access_id)
13 byte_key = binascii.a2b_hex(access_key)
14 cipher = DES3Cipher(key=bytedes_key, mode=blockalgo.MODE_ECB)
15 plain_id = cipher.decrypt(byte_id)
16 print(type(plain_id))
17 plain_id = plain_id[0:len(plain_id) - int(plain_id[-1])].decode('utf-8')
18 plain_key = cipher.decrypt(byte_key)
19 plain_key = plain_key[0:len(plain_key) - int(plain_key[-1])].decode('utf-8')
20 return (plain_id, plain_key)
21
22
23 if __name__ == '__main__':
24 SECRET_KEY = (
25 0x12, 0x22, 0x4F, 0x58, 0x88, 0x10, 0x40, 0x38,
26 0x28, 0x25, 0x79, 0x51, 0xCB, 0xDD, 0x55, 0x66,
27 0x77, 0x29, 0x74, 0x98, 0x30, 0x40, 0x36, 0xE2
28 )
29 access_id = '7159603AA8DAA73353C6C29F6B0BDC42A3BC6F34C78D2BFC'
30 access_key = '3DC1BBB7AAE5D8D0469C76899B2B3274902937AE833089D2F9F9D51AA0F7447A'
31 result = _decode_ossauth(access_id, access_key, SECRET_KEY)
32 print(result)