Aes Encryption Example Python


Example: python AES

from Crypto.Cipher import AES  import binascii,os import random, string  iv = os.urandom(16) aes_mode = AES.MODE_CBC key = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(16)) print(key) encryptor = AES.new(key, aes_mode, iv) def aes_encrypt(plaintext):     plaintext = convert_to_16(plaintext)      ciphertext = encryptor.encrypt(plaintext)     return ciphertext  def convert_to_16(plaintext): #Overcome the drawback of plaintxt size which should be multiple of len(iv)     add = 16 - (len(plaintext) % 16)     return(plaintext + ' ' * add)   Encrypted = aes_encrypt('Jaisal ') print("Encrypted message :",Encrypted)

Comments

Popular posts from this blog

Chemistry - Bond Angles In NH3 And NCl3

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?