How to encrypt and decrypt text using AES in python?


To see how to do simple encryption and decryption of the given text message using AES.

   Get the input message text.

   In AES the same key used for both encryption and decryption.

   Generate the secret key.

   Define the mode of AES.

   Encrypt the message using cipher.encrypt().

   Decrypt the message using cipher.decrypt().

#import crypto and base64

from Crypto.Cipher import AES

import base64

message =

‘FirstSoft Technologies Pvt Ltd’.rjust(32)

print(“Actual message is\n”,message)

secret_key = ‘1234589648789658’

#define AES mode

cipher =


#encode the message text

encryption = base64.b64encode



#print the encoded message

print(“The encrypted message is\n”,encryption)

#decode the message

decryption = cipher.decrypt



#print the decode

print (“Original message after decryption


Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit