Coder Social home page Coder Social logo

encryptdir.py's Introduction

encryptdir.py

a python script to encrypt all files in a directory with a public rsa key.

Usage

  1. Generate a rsa key pair

    python encryptdir.py gen-keys

    This creates a 4096 rsa key file mykey.pem and it's public key file is: mykey.pem.pub

  2. Create your input folder if not exists

    mkdir input
  3. Create some test data (optional)

    python encryptdir.py gen-test-files 5
  4. Encrypting

    python encryptdir.py encrypt

    This encrypts all files in ./input/ to ./output/. Files which are exists in output will be ignored. After encrypting, the output folder looks like:

    root@FreeBSD:~/encryptdir # ls -la output
    total 324015
    drwxr-xr-x  2 root  wheel         14 Dec 30 02:13 .
    drwxr-xr-x  7 root  wheel         14 Dec 30 02:11 ..
    -rw-r--r--  1 root  wheel  331375424 Dec 29 23:29 31c3-5960-en-Revisiting_SSL_TLS_Implementations_hd.mp4.gz.enc
    -rw-r--r--  1 root  wheel        512 Dec 29 23:27 31c3-5960-en-Revisiting_SSL_TLS_Implementations_hd.mp4.key.enc
    -rw-r--r--  1 root  wheel       1392 Dec 29 23:29 test-0.gz.enc
    -rw-r--r--  1 root  wheel        512 Dec 29 23:29 test-0.key.enc
    -rw-r--r--  1 root  wheel       1392 Dec 29 23:29 test-1.gz.enc
    -rw-r--r--  1 root  wheel        512 Dec 29 23:29 test-1.key.enc
    -rw-r--r--  1 root  wheel       1392 Dec 29 23:29 test-2.gz.enc
    -rw-r--r--  1 root  wheel        512 Dec 29 23:29 test-2.key.enc
    -rw-r--r--  1 root  wheel       1392 Dec 29 23:29 test-3.gz.enc
    -rw-r--r--  1 root  wheel        512 Dec 29 23:29 test-3.key.enc
    -rw-r--r--  1 root  wheel       1392 Dec 29 23:29 test-4.gz.enc
    -rw-r--r--  1 root  wheel        512 Dec 29 23:29 test-4.key.enc
    
  5. Decrypting

    python encryptdir.py decrypt -in ./folder-with-encrypted-files/ -out ./target-folder/
  6. Test encryption and decryption You can also test encryption and decryption.

    #mkdir input && insert some test files (optional)
    python encryptdir.py test

    This encrypts and decrypts your test files. If ./input/ does not exists, the folder will be automatically created and some test data will be inserted.

Customizing

In encryptdir.py you can customize following parameters:

  • Folders:

    # default input folder only for encrypting
    INPUTDIR="./input"
    # default output folder only for encrypting
    OUTPUTDIR="./output"
    # default temp folder for en-/decrypting
    TMPDIR="./tmp"
  • Key files

    # location of rsa private key file. 
    # Keep this file save! only needed for decryption!
    DEFAULT_KEY_FILE="./mykey.pem"
    # location of rsa public key file.
    DEFAULT_PUB_KEY_FILE="./mykey.pem.pub"
  • Key sizes

    # File/key size for symmetric encryption
    AES_KEY_FILE_SIZE=256
    # RSA key size. Only needed for RSA key creation. (encryptdir.py gen-keys)
    RSA_KEY_SIZE=4096
  • symmetric cipher routines Sym. cipher routines used for each file en-/decryption. Support Types

    # used symmetric cipher routines
    # see https://www.openssl.org/docs/apps/enc.html#supported_ciphers
    SYMMETRIC_ENCRYPTION_CASC = [
      'aes-256-cbc',
      'bf',
      'cast5-cbc'
    ]

Commandline help

python encryptdir.py --help

or for specific command:

python encryptdir.py decrypt --help

encryptdir.py's People

Contributors

medoni avatar

Watchers

 avatar  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.