If we are using a block cipher, then we should select one block cipher mode of operation. These block cipher modes of operation provide better security. In a block cipher, the input plaintext is divided into several equal-sized blocks and the last block is padded. After that, each of the plaintext blocks is encrypted. But, if we encrypt the plaintext blocks individually without using any secure block cipher mode of operation, then the same plaintext block will always result in the same ciphertext block if the same key is used. As a result, an attacker can easily analyze the ciphertext and derive information about the key or the plaintext.
In our previous article, we discussed how to implement AES in Python. We also discussed how to implement PKCS#7 padding and unpadding in Python.
KEYSIZE = 16 plaintext = 'This is secret'.encode() key = getKey(KEYSIZE) padded_plaintext = pkcs7Pad(plaintext, 16) ciphertext = encryptAES(padded_plaintext, key) print(ciphertext) decrypted_text = pkcs7Unpad(decryptAES(ciphertext, key)) print(decrypted_text.decode())
Interested readers who want a detailed explanation of the above code please refer to the said articles.
In our previous article, we implemented the AES algorithm in Python, but for simplicity, we encrypted one plaintext block at a time. In this article, we would discuss how to implement the CBC mode of operation in Python.
In this article, we will discuss:
-
How does the Cipher Block Chaining (CBC) mode of operation work?
-
How to implement CBC mode of operation in Python?
0 Comments