Giter VIP home page Giter VIP logo

rsaencryptionanddecryption's Introduction

RsaEncryptionAndDecryption

To run


python3 -e file_to_save_ecnrypted_message file_with_plain_text_message  

python3 -d file_with_ecnrypted_message file_to_save_plain_text_message  

-e or -d to indicate whether to encrypt or decrypt the file  

This project helps in encrypting data with a public key and decrypting with private key

It uses the Crypto library to generate RSA keys, encrypt data with AES, and encrypt the AES key with RSA. The resulting encrypted data and keys are then saved to files.

When the script is run, it expects three command-line arguments:

The path to the input file

The path to the output file

If the operation argument is -e, the script generates RSA keys, encrypts the input file with AES, and then encrypts the AES key with RSA. The encrypted data is saved to the output file.

If the operation argument is -d, the script decrypts the AES key using the private RSA key, then uses the decrypted key to decrypt the input file with AES. The decrypted data is saved to the output file.

If the operation argument is not recognized, the script prints an error message.

Note that the script uses a fixed AES key (b'Sixteen byte key'), which is not secure. In a real application, you would want to generate a random key for each encryption operation.

The Crypto library is a Python library that provides various cryptographic functions and algorithms, including symmetric and asymmetric encryption, digital signatures, and hashing. In this code, we use it to generate RSA keys, encrypt data with AES, and encrypt the AES key with RSA.

The AESEncryption class is the main class that performs the encryption and decryption operations. When an instance of this class is created, it reads the three command-line arguments (operation, file1, and file2) and stores them as instance variables. The operation argument indicates whether to encrypt or decrypt the file, and file1 and file2 are the paths to the input and output files, respectively.

The createKeys method generates an RSA key pair with a length of 2048 bits. It then exports the public and private keys to two separate files (publicKey.pem and privateKey.pem).

The encrypt method reads the contents of the input file (file2) and pads the data with a block size of 16 bytes (the AES block size). It then encrypts the padded data with AES using the AES key (self.aes_key). After that, it imports the public RSA key from publicKey.pem and uses it to encrypt the AES key with RSA. The resulting encrypted data and key are then saved to the output file (file1).

The decrypt method reads the encrypted data from the input file (file1) and imports the private RSA key from privateKey.pem. It then uses the private key to decrypt the AES key, which was encrypted with RSA. The decrypted AES key is used to decrypt the data with AES. The decrypted data is then saved to the output file (file2).

Finally, the AESEncryption() statement at the end of the code creates an instance of the AESEncryption class, which triggers the encryption or decryption operation based on the operation argument. If the operation argument is not recognized, the script prints an error message.

I hope this provides a more detailed explanation of the code! Let me know if you have any other questions. And feel free to raise any issues or forking the project

rsaencryptionanddecryption's People

Contributors

cyrilcodepro avatar qarani-m avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

qarani-m

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.