def encrypt(self, plaintext):
"""CBC encryption."""
cipher = AES.new(key=self._key, mode=AES.MODE_ECB)
# The full URL is not necessary for this setup, so I am just encrypting
# the plaintext as it is. I don't even need to support padding.
prev_ct = self._iv
block_index = 0
ciphertext = b''
# The loop simulates encryption through AES in CBC mode.
while block_index < len(plaintext):
block = plaintext[block_index : block_index + AES.block_size]
final_block = strxor(block, prev_ct)
cipher_block = cipher.encrypt(final_block)
prev_ct = cipher_block
ciphertext += cipher_block
block_index += AES.block_size
return ciphertext
评论列表
文章目录