Giter VIP home page Giter VIP logo

security's Introduction

Security

This library was created to act as a wrapper for more sophisticated cryoptographic and security packages.

Installation

Installing to use in your own scripts in a virtual environment?

pip install git+https://github.com/pmp47/Security

Installing to edit this code and contribute? Clone/download this repo and...

pip install -r requirements.txt

Usage

Secret sharing is useful for splitting sensitive information.

#sensitive info
secret_str = 'test secret'

#minimum shares required to recombine into secret
min_req = 5

#total shares to create
total_shares = 10

#split the secret into a list of shares
shares = Secrets.Sharing.Split(secret_str,min_req=min_req,total_shares=total_shares)

Cryptographic hashing is useful for truncating data into a fixed length, or creating unique identifiers.

#data to hash can be of any length
string_to_hash = 'hello world'

#the returned hash is a fixed bit length in this case of SHA256
hashed_str = Hashing.HashStr(string_to_hash)

#can use other hash types such as a constant time bcrypt
bcrypt_str = Hashing.HashStr(string_to_hash,hash_type='bcrypt')

The centerpiece of the library is encryption/decryption. Public key (Asymmetric) generation, encryption, and decryption are useful for transmitting data across untrusted networks.

#first we need an asymmtric key (public/private)
asymKeys = Encrypting.Asymmetric.GenerateKey('my new keys',2) #high lvl -> high cpu time

#perhaps we have an object as json on a client
obj_str = 'this is an object as a string' 

#the obj is encrypted using the public key on the client
encrypted_str = Encrypting.Asymmetric.Encrypt(obj_str,asymKeys['public'])

#the encrypted data can be sent to the server where the private key is
decrypted_str = Encrypting.Asymmetric.Decrypt(encrypted_str,asymKeys['private'])

Symmetric encryption is useful for storing/sending large data as asymmetric encryption is limited by the level of the public key.

#lets make a passphrase to remember
passphrase = 'the_longer_the_passphrase_the_better_in_terms_of_preventing_cracking'

#and get the data to encrypt as bytes
data_to_encrypt = b'secret string to encrypt symmetrically'

#then encrypt to secure
encrypted_data = Encrypting.Symmetric.Encrypt(data_to_encrypt,passphrase)

#and decrypt later to reveal
decrypted_data = Encrypting.Symmetric.Decrypt(encrypted_data,passphrase)

Notes

Security in any application shouldn't be taken lightly. While this package provides a simple way to use the underlying cryptographic primitives, it still may not meet your requrements.

security's People

Contributors

pmp47 avatar

Watchers

 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.