Coder Social home page Coder Social logo

cryptokit's Introduction

Build Status codecov PyPI PyPI

cryptokit

cryptokit is a cryptography kit base on Cryptography(https://github.com/pyca/cryptography)

Document

You can find more information in the cryptokit documentation.

Feature Support

  • AES Cryptography
  • RSA Cryptography
  • ED25519
  • x25519 key exchange
  • HKDF

Installation

pip install cryptokit

AES usage

>>> from cryptokit import AESCrypto
>>> message = "hello cryptokit"
>>> crypto = AESCrypto('WDMG1e38igW53YuxkE0SsKUDeLbULAtL', 'm2VYHdx41zRgvg6f')
>>> data = crypto.encrypt(message)
>>> b'\xaa<\x9d\xe9\xde\x0b\xd7\xe9\xfd\xac\xfc\xdd\x9f\xe2V\xd4'
>>> crypto.decrypt(data)
>>> 'hello cryptokit'

RSA usage

>>> from cryptokit import RSACrypto
>>> private_key = RSACrypto.generate_private_key(2048)
>>> public_key = private_key.public_key()
>>> message = 'Hello cryptokit'
>>> ciphertext = RSACrypto.encrypt(message, public_key, algorithm='sha256')
>>> plaintext = RSACrypto.decrypt(ciphertext, private_key, algorithm='sha256')
>>> plaintext == message
True

PFX usage

>>> from cryptokit import load_pfx, get_pubkey_from_pfx
>>> pkcs12 = load_pfx(pfx_file, password='password')
>>> cert = pkcs12.get_certificate()
>>> pubkey = get_pubkey_from_pfx(pfx_file, password='password')
# or use cert get pubkey
>>> pubkey = cert.get_pubkey().to_cryptography_key()

>>> from cryptokit import generate_pfx
>>> pfx_data = generate_pfx(cert, friendly_name, private_key)

Create csr

from cryptokit import generate_csr
from cryptokit.rsa import RSACrypto

private_key = RSACrypto.generate_private_key(2048)
payload = {
    'country_name': 'US',
    'state_or_province': 'California',
    'locality_name': 'San Francisco',
    'org_name': 'My Company',
    'common_name': 'mysite.com',
    'dns_list': ['mysite.com', 'www.mysite.com', 'subdomain.mysite.com']
}

csr_data = generate_csr(private_key, encoding='pem', algorithm='sha256', **payload)

with open('/path/to/csr.pem', 'wb') as f:
    f.write(csr_data)

ED25519

Generate key pair

from cryptokit import ed25519

# raw Cryptography object
private_key_obj, public_key_obj = ed25519.generate_ed25519_key_pair()

# hex
private_key_hex, public_key_hex = ed25519.generate_ed25519_key_pair("hex")

# base64 encode
private_key_b64, public_key_b64 = ed25519.generate_ed25519_key_pair("base64")

# bytes
private_key_bytes, public_key_bytes = ed25519.generate_ed25519_key_pair("bytes")

ED25519 key exchange

from cryptokit import ed25519

private_key_hex = "private_key_hex"

target_public_key_hex = "target_public_key_hex"


share_secret_hex = ed25519.get_share_secret_from_hex(private_key_hex, target_public_key_hex)

HKDF

from cryptokit import hkdf

device_key = hkdf.get_hkdf_device_key(bytes.fromhex("hex format string"))

ChangeLog

changelog

License

MIT. See LICENSE for more details.

cryptokit's People

Contributors

istommao avatar

Stargazers

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