Main program for a secured client-srver communication.
This commit is contained in:
parent
a472b62e19
commit
2f3f9f47aa
6 changed files with 337 additions and 21 deletions
27
encryption.py
Normal file
27
encryption.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import os
|
||||
|
||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||
from cryptography.hazmat.primitives import padding
|
||||
|
||||
|
||||
key = os.urandom(16)
|
||||
|
||||
# iv = os.urandom(16)
|
||||
# iv_2 = os.urandom(16)
|
||||
|
||||
iv_1 = b'\x00' * 16
|
||||
iv_2 = b'\x00' * 16
|
||||
|
||||
cipher = Cipher(algorithms.AES(key), modes.CBC(iv_1))
|
||||
print(f"block size AES: {algorithms.AES.block_size}")
|
||||
|
||||
encryptor = cipher.encryptor()
|
||||
ciphertext = encryptor.update(b"a secret message") + encryptor.finalize()
|
||||
print(f"ciphertext={ciphertext!r}")
|
||||
print(f"len(ciphertext)={len(ciphertext)}")
|
||||
|
||||
cipher_2 = Cipher(algorithms.AES(key), modes.CBC(iv_2))
|
||||
decryptor = cipher_2.decryptor()
|
||||
|
||||
res = decryptor.update(ciphertext) + decryptor.finalize()
|
||||
print(f"res={res!r}")
|
Loading…
Add table
Add a link
Reference in a new issue