Git Product home page Git Product logo

plasm's Introduction

PynacL AbStraction Module

Plasm is a simple PyNaCl abstraction module to easily integrate file encryption into python projects. It makes key generation and file encryption/decryption very simple. Plasm uses the sealedBox construct. The sealedBox uses key pairs of public and private keys. This allows encrypt using only a public key. That way the private key required for decryption can be stored in a safe place away from the machine that does the encryption. The private key is also encrypted itself using a password. This password is specified during the creation of the key pair. During decryption of a file encrypted with the public key, the private key is first decrypted using the password specified before it's creation and then used to decrypt the file.

If you are willing to dive deeper or want to customize more than what plasm allows to, feel free to check out PyNaCl's documentation and use it directly.

Usage

Generating keys:

  • memlimit is optional and specifies the amount of RAM occupied for encrypting the private key in bytes. It's set to 1073741824 bytes (1,07 gigabytes) by default, because that's the memlimit for sensitive data libsodium suggests. If you specify a memlimit exceeding the free RAM your device can offer, creating the key will fail. If your encrypting device (e.g. a Raspberry Pi with ~500 megabytes of RAM) can't offer the default, I suggest creating the keys on a device that does and transferring them to the other device instead of weakening the encryption of your private key by creating it with a lower memlimit.
from plasm import gen_keys

gen_keys.generate_key_pair(private_key_location, public_key_location, password, memlimit=1073741824)

Encrypting a file

  • remove_input_file is optional and False by default.
from plasm import encrypt

encrypt.encrypt_file(my_file, public_key_location, remove_input_file=True)

Encrypting all files in a directory:

  • outfile_extension is optional and set to ".crypt" by default
  • remove_input_file is optional and False by default.
from plasm import encrypt

encrypt.encrypt_files_in_dir(directory, public_key_location, outfile_extension=".crypt", remove_input_file=False):

Decrypting a file:

from plasm import decrypt

decrypt.decrypt_file(encrypted_file, private_key_location, password)

Decrypting all files with a certain extension in a directory:

  • infile_extension is optional and set to ".crypt" by default
from plasm import decrypt

decrypt.decrypt_files_in_dir(directory, private_key_location, password, infile_extension=".crypt"):

Testing

plasm offers a test suite based on pytest. To run all tests, move to the root directory of plasm and run pytest:

python -m pytest tests

If you want a coverage report, use this command:

python -m pytest --cov=plasm --cov-report term-missing tests

plasm's People

Contributors

va1entin avatar

Watchers

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