Skip to content

Snippet for encrypting/decrypting messages in python using Cryto.Cypher AES

License

Notifications You must be signed in to change notification settings

edilio/aes-cypher-snippet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aes-cypher-snippet

Snippet for encrypting/decrypting messages in python using Cryto.Cypher AES

Requirements

pycrypto==2.6.1

How to test it

  • pip install -r requirements.txt
  • cp sample.env .env
  • edit .env changing SECRET_KEY
  • source .env && ./cypher.py

The snippets

def encrypt(msg):
    """
    msg should be multiple of 16
    """
    msg16 = msg + ' '*(16 - len(msg) % 16)
    obj = AES.new(SECRET_KEY[:16], AES.MODE_CBC, SECRET_KEY[-16:])
    encrypted = obj.encrypt(msg16)
    return base64.b64encode(encrypted)
def decrypt(msg):
    dec_msg = base64.b64decode(msg)
    obj = AES.new(SECRET_KEY[:16], AES.MODE_CBC, SECRET_KEY[-16:])
    return obj.decrypt(dec_msg).strip()

About

Snippet for encrypting/decrypting messages in python using Cryto.Cypher AES

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages