import binascii
from Crypto.Cipher.DES3 import DES3Cipher
from Crypto.Cipher import blockalgo
def _decode_ossauth(access_id, access_key, secret_key):
bytedes_key = ""
for b in secret_key:
bytedes_key += "%c" % b
print((type(bytedes_key), len(bytedes_key)))
byte_id = binascii.a2b_hex(access_id)
byte_key = binascii.a2b_hex(access_key)
cipher = DES3Cipher(key=bytedes_key, mode=blockalgo.MODE_ECB)#这一行报错
plain_id = cipher.decrypt(byte_id)
plain_id = plain_id[0:len(plain_id) - int(binascii.b2a_hex(plain_id[-1]))]
plain_key = cipher.decrypt(byte_key)
plain_key = plain_key[0:len(plain_key) - int(binascii.b2a_hex(plain_key[-1]))]
return (plain_id, plain_key)
if __name__ == '__main__':
SECRET_KEY = (
0x12, 0x22, 0x4F, 0x58, 0x88, 0x10, 0x40, 0x38,
0x28, 0x25, 0x79, 0x51, 0xCB, 0xDD, 0x55, 0x66,
0x77, 0x29, 0x74, 0x98, 0x30, 0x40, 0x36, 0xE2
)
access_id = '7159603AA8DAA73353C6C29F6B0BDC42A3BC6F34C78D2BFC'
access_key = '3DC1BBB7AAE5D8D0469C76899B2B3274902937AE833089D2F9F9D51AA0F7447A'
result = _decode_ossauth(access_id, access_key, SECRET_KEY)
print(result)
报错信息:
ValueError: Invalid key size (must be either 16 or 24 bytes long)
from Crypto.Cipher.DES3 import DES3Cipher
from Crypto.Cipher import blockalgo
def _decode_ossauth(access_id, access_key, secret_key):
bytedes_key = ""
for b in secret_key:
bytedes_key += "%c" % b
print((type(bytedes_key), len(bytedes_key)))
byte_id = binascii.a2b_hex(access_id)
byte_key = binascii.a2b_hex(access_key)
cipher = DES3Cipher(key=bytedes_key, mode=blockalgo.MODE_ECB)#这一行报错
plain_id = cipher.decrypt(byte_id)
plain_id = plain_id[0:len(plain_id) - int(binascii.b2a_hex(plain_id[-1]))]
plain_key = cipher.decrypt(byte_key)
plain_key = plain_key[0:len(plain_key) - int(binascii.b2a_hex(plain_key[-1]))]
return (plain_id, plain_key)
if __name__ == '__main__':
SECRET_KEY = (
0x12, 0x22, 0x4F, 0x58, 0x88, 0x10, 0x40, 0x38,
0x28, 0x25, 0x79, 0x51, 0xCB, 0xDD, 0x55, 0x66,
0x77, 0x29, 0x74, 0x98, 0x30, 0x40, 0x36, 0xE2
)
access_id = '7159603AA8DAA73353C6C29F6B0BDC42A3BC6F34C78D2BFC'
access_key = '3DC1BBB7AAE5D8D0469C76899B2B3274902937AE833089D2F9F9D51AA0F7447A'
result = _decode_ossauth(access_id, access_key, SECRET_KEY)
print(result)
报错信息:
ValueError: Invalid key size (must be either 16 or 24 bytes long)