def basic_encrypt(cls, key, plaintext):
assert len(plaintext) >= 16
aes = AES.new(key.contents, AES.MODE_CBC, '\0' * 16)
ctext = aes.encrypt(_zeropad(plaintext, 16))
if len(plaintext) > 16:
# Swap the last two ciphertext blocks and truncate the
# final block to match the plaintext length.
lastlen = len(plaintext) % 16 or 16
ctext = ctext[:-32] + ctext[-16:] + ctext[-32:-16][:lastlen]
return ctext
评论列表
文章目录