Git Product home page Git Product logo

simpleaes's Introduction

Simple AES

Find more information about this library HERE

An easy way to use the aes CBC mode of pycryptodome. To use this library just drag and drop the 'simpleAES.py' file into your work bench and import it to your program.

Dependencies


Check your pip version with:

pip --version

if it is for python3 then use the following command.

pip install pycryptodome

else try to use the pip3 comand:

pip3 install pycryptodome

Code examples

Automated key generation:

from simpleAES import *

key = keyGenerator()
IV = ivGenerator()

aes = simpleAES(key, IV)

text = "This is a test".encode()

ciphertext = aes.encrypt(text)
plaintext = aes.decrypt(ciphertext)

print("This is the ciphertext:", ciphertext)
print("This is the plaintext:", plaintext.decode())

Setup custom keys:

from simpleAES import *

key = "This is a key".encode()
iv = "This is an IV".encode()
salt = "This is a salt".encode()

# The hash option will hash the key with the sha256 algorithm
# and the IV with the md5 algorithm with the salt to
# prevent brute force attacks 

aes = simpleAES(key, iv, hash=True, salt=salt)

text = "This is a text".encode()

ciphertext = aes.encrypt(text)
plaintext = aes.decrypt(ciphertext)

print("ciphertext:", ciphertext)
print("plaintext:", plaintext.decode())

Store the key to a file:

from simpleAES import *

key = keyGenerator()
IV = ivGenerator()

aes = simpleAES(key, IV)

path = "key.key"

aes.extractKey(path)

Store the key to an encrypted file:

from simpleAES import *

key = keyGenerator()
iv = ivGenerator()

aes = simpleAES(key, iv)

key2 = "abcde".encode()
iv2 = "12345".encode()
salt = "qwerty".encode()

aes2 = simpleAES(key, iv , hash=True, salt=salt)

path="encryptedKey.key"

#It will encrypt the file with the 'aes2' object.

aes.extractEncryptedKey(aes2, path)

Load the key from file:

from simpleAES import *

path = "key.key"

data = loadKeyFromFile(path)

key = data[0]
IV = data[1]

# When you load a key from file do not set the 
# hash value to True or use the salt option,
# because in the file are stored the hashed values and not
# the original keywords.

aes = simpleAES(key, IV)

Load the key from encrypted file:

key = "abcde".encode()
iv = "12345".encode()
salt = "qwerty".encode()

aes = simpleAES(key, iv, hash=True, salt=salt)

path="encryptedKey.key"

data = loadKeyFromEncryptedFile(aes, path)

key = data[0]
iv = data[1]

aes = simpleAES(key, iv)

simpleaes's People

Contributors

andreaskarageorgos avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.