Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 725 Bytes

README.md

File metadata and controls

32 lines (26 loc) · 725 Bytes

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