Is CBC 128bit encryption vulnerable if I expose a start-of-text pattern?

136 views Asked by At

I'm doing encryption with my program, but I'm worried about exposing an initial layout in the plaintext.

As you can see, I intend to encrypt sha256 of the plain text plus the plain text, all together, I will use the sha256 to calculate integrity and check if the content was not changed.

encrypt: sha256 of plaintext + plaintext, padding

And as you can see, I'm concerned that an attacker might know that the first few bytes are a pattern of letters and numbers that are part of a sha256 of the original message.

In this case, the IV is not secret, and the attacker could have the IV and the Encryption.

My question is if my method of use is safe or an attacker could get lucky.

An example:

#need: pip install pycryptodome

from Crypto.Cipher import AES;
from Crypto.Util.Padding import pad;
from Crypto.Random import get_random_bytes;
from hashlib import sha256;


textPlain = input("Enter text plain: ").encode(); #(secret)
shaMsg = sha256(textPlain).hexdigest();

password = pad(b"APasswordExample", 16, "iso7816"); #(secret)

iv = get_random_bytes(16); #(no secret)

secretBytes = shaMsg.encode()+textPlain;
secretBytes = pad(secretBytes, 16, "iso7816");

cip = AES.new(password, AES.MODE_CBC, iv);
encrypted = cip.encrypt(secretBytes);

So I would like you to give me your opinion about my encryption

Thanks :D

0

There are 0 answers