DhanushNehru / Python-Scripts

A curated list of python scripts for automating your tasks
https://dhanushnehru.github.io/Python-Scripts/
MIT License
551 stars 259 forks source link

AES Encryption and Decryption #351

Open sam14243 opened 1 month ago

sam14243 commented 1 month ago

Is your feature request related to a problem? Please describe. There is a need for a secure way to encrypt and decrypt files for safe storage.

Describe the solution you'd like Python scripts that implement AES encryption and decryption for files with a key.

Describe alternatives you've considered While online tools exists, they require users to trust third-party services with their files.

Please assign me this issue for hacktoberfest. Thanks!

hc671123 commented 1 month ago

Hi a few questions regarding your issue:

  1. In which mode would you like to operate AES (GCM, ECB, etc.)?
  2. Would you like to use an existing library like pycryptodomex or build the implementation from scratch?

If you are fine with using a library like pycryptodomex it should not take long to code a small script which en- and decrypts files...

sam14243 commented 4 weeks ago

Hi, I have built an implementation from scratch which encrypts block by block(so technically in ECB mode). If some other mode is preferred, i can code a script using the libraries as mentioned.

hc671123 commented 4 weeks ago

Hi, Thanks for your fast reply! If you want the Script to encrypt files with good crypto, I would recommend using AES-GCM as it is safer than AES-ECB and also ensures data integrity... But if you want the script to be a bit more educational I would find a from scratch implementation very nice as one may better understand what's going on.

I wish you all a great day

hc671123 commented 4 weeks ago

Another Idea: If you want you could maybe let the user decide which Mode he wants to use... If you want I can also give you an implementation of AES-GCM 256 Bit with pycryptodomex I implemented a while ago.

sam14243 commented 4 weeks ago

Hi again, This repo is mainly for automating tasks right, So I guess using the library(in GCM mode) and letting the user decide will be the best option here. Also, I am trying to read a file(basically input file and not text), encrypt it and store the encrypted file. If you could provide me with AES-GCM 256 code, I'll modify it to add the other implementation(128 and 192) as well. Let me know what you think!

sam14243 commented 4 weeks ago

Also, can any of the maintainers assign me this issue pls? Thanks!

hc671123 commented 4 weeks ago

Hi, Sounds good, I'll make a public repo with the Code and link it when im done with it. I'll just double check everything and translate my comments into English. I suppose it will be ready by the 27th... I'll also add a README with some thinks to consider regarding AES GCM in general and my implementation in particular

sam14243 commented 3 weeks ago

Sounds good, btw @hc671123, are you a maintainer of this repo or you want to contribute to this issue(in general or for hacktoberfest)?

hc671123 commented 3 weeks ago

I am not a maintainer but I'll contribute on another Issue and I'll give you the AES GCM Code... I could also contribute to this issue but in the moment I dont have much free time

sam14243 commented 3 weeks ago

Ah, alright cool, I'll work on this issue then

sam14243 commented 3 weeks ago

Hi, @DhanushNehru, can you pls review the problem and assign me this issue?

hc671123 commented 3 weeks ago

Hi again, My implementation is in this Repo: https://github.com/hc671123/AES_GCM_Python

some ideas I just had regarding the file encryption / decryption: Maybe it would be nice to have some kind of Key Managment System, which ensures that maybe every file has its own key and a deterministic nonce which increments with changes to the file?! And maybe one could add a possibility to encrypt a file with a password using a key derivation function or by encrypting the key with the password with Vigenere or something like that... But these are just ideas I had you can also take a completely different approach!

If you have any questions regarding my implementation you are free to ask them anytime and I wish you a pleasant day!

sam14243 commented 3 weeks ago

Hi there, thanks for the implementation! For now, let's implement the basic script and later we can add these ideas. I'll complete my part now. Have a good day!