Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to encrypt and decrypt text using AES in python?

Description

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

Process

   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().

Sample Code

#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 = AES.new

(secret_key,AES.MODE_ECB)

#encode the message text

encryption = base64.b64encode

(cipher.encrypt(message))

print(“\n”)

#print the encoded message

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

#decode the message

decryption = cipher.decrypt

(base64.b64decode(encryption))

print(“\n”)

#print the decode

print (“Original message after decryption

is\n”,decryption)

Screenshots
encrypt and decrypt text using AES in python