【发布时间】:2019-03-07 21:02:48
【问题描述】:
我正在使用 PyAES 制作一个 AES 加密/解密程序,当我打印输出时,它看起来像这样:
b'\xb6\xd52#\xb1\xd5a~.L\xc2M\x83U\xb3\xf6'(加密)
b'TextMustBe16Byte'(明文)
我想去掉 b 和撇号,这样前端看起来更干净。
我的代码:
import pyaes
import os
# A 256 bit (32 byte) key
key = os.urandom(32)
# For some modes of operation we need a random initialization vector
# of 16 bytes
iv = os.urandom(16)
aes = pyaes.AESModeOfOperationCBC(key, iv = iv)
plaintext = "TextMustBe16Byte"
ciphertext = aes.encrypt(plaintext)
# '\xd6:\x18\xe6\xb1\xb3\xc3\xdc\x87\xdf\xa7|\x08{k\xb6'
print(ciphertext)
# The cipher-block chaining mode of operation maintains state, so
# decryption requires a new instance be created
aes = pyaes.AESModeOfOperationCBC(key, iv = iv)
decrypted = aes.decrypt(ciphertext)
print(decrypted)
【问题讨论】: