Giter Site home page Giter Site logo

crimsondevil / rsa-key-generation-aes-encryption Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 4 KB

Generating public and private keys using RSA Algorithm; Encrypting files using AES-128 and encrypting the AES key. using the RSA public key generated above.

Python 100.00%
rsa-algorithm rsa-cryptosystem rsa-aes public-key-cryptography private-keys aes-128 aes-encryption cryptography

rsa-key-generation-aes-encryption's Introduction

RSA-key-generation-AES-encryption

DISCLAIMER: All the screenshots are based in a Windows OS environment, so instead of "cat" command, I have used "type" command to view the files on cmd.

genkeys.py

In this file, a name is given as an argument from the command line along with the script to run the file. This name is used to generate two files, one for storing the public key and other for storing the private key generated from the RSA key generation technique. The program starts with the generation of 2 large random prime numbers, p and q, using the Miller-Rabin's primality test algorithm. With this, the values of n and totient, t are calculated. Using the variables above, GCD and MOD Inverse was calculated to generate the public key, e and the private key, d. The values (n, e) are written in the public key file and the values (n, d) are written in the private key file. The key size used is 1024.

Sample commands to run the file "genkeys.py" :-

py genkeys.py alice
py genkeys.py bob

crypt.py

In this file, we have used an argument parser to run the functions according to the selection between the encryption and decryption of a file. In the beginning, a random 16 bytes key is generated for AES-128 encryption. Then, the plaintext from the specified text file is encrypted using this key and the AES Encryption algorithm imported from the pyaes module. The key used for AES is then encrypted using the RSA public key from the previous file. Both, the cipher text and the encrypted AES key is written into a .cip file. For decryption, the .cip file is accessed along with the RSA private key. Using the private key, the encrypted AES key is decrypted for use in AES Decryption algorithm. The resulting file is stored in another file.

Sample commands to run the file "crypt.py" :-

type message.txt
py crypt.py -e bob.pub message.txt message.cip

type message.cip
py crypt.py -d bob.prv message.cip secret.txt
type secret.txt


type message1.txt
py crypt.py -e alice.pub message1.txt message1.cip

type message1.cip
py crypt.py -d alice.prv message1.cip secret1.txt
type secret1.txt

rsa-key-generation-aes-encryption's People

Contributors

crimsondevil avatar

Watchers

 avatar  avatar

Forkers

azizadelsub

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.