johnstrong1 / aes-cypher-snippet

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

License:MIT License


Languages

Language:Python 100.0%