在Python中处理密钥
python
from binascii import unhexlify
from base64 import b64encode
import struct
key_hex = b'101112131415161718191a1b1c1d1e1f'
key_bytes = unhexlify(key_hex)
print(len(key_hex), key_hex)
print(len(key_bytes),'bytes', '=', len(key_bytes)*8,'bits,', key_bytes)
print(b64encode(key_bytes))
k = struct.unpack('>llll', key_bytes)
print(*k)
k_bytes_decode = struct.pack('>llll', *k)
print(len(key_bytes),'bytes', '=', len(key_bytes)*8,'bits,', k_bytes_decode)
shell
32 b'101112131415161718191a1b1c1d1e1f'
16 bytes = 128 bits, b'\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'
b'EBESExQVFhcYGRobHB0eHw=='
269554195 336926231 404298267 471670303
16 bytes = 128 bits, b'\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'
[Finished in 110ms]