Giter Site home page Giter Site logo

labteral / digsig Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 55 KB

Digital Signature Toolkit for Python

Home Page: https://pypi.org/project/digsig/

License: GNU General Public License v3.0

Shell 0.49% Python 99.51%
rsa p12 pkcs12 fmnt digital-signature pfx

digsig's Introduction

DigSig

Downloads PyPi GitHub releases License

Digital signatures with Python

Buy Me A Coffee

The private key detection is automatic with the class PrivateKey. It currently works with RSA (X.509 with PKCS#12 files: .p12, or .pfx) and with ECDSA (Ethereum account exported in a JSON file).

Install

pip install digsig

Load keys

Automatic detection

RSA (X.509)

from digsig import PrivateKey, PublicKey

private_key = PrivateKey.get_instance('fnmt.p12', 'p4ssw0rd')
signature = private_key.sign('message')

# public_key = private_key.public_key
public_key = PublicKey.get_instance('fnmt.pem')

ECDSA (Ethereum)

from digsig import PrivateKey, PublicKey

private_key = PrivateKey.get_instance('ethereum.json', 'p4ssw0rd')

signature = private_key.sign('message')

public_key = private_key.public_key

RSA

from digsig import RsaPrivateKey, RsaModes, RsaFormats

private_key = RsaPrivateKey('fnmt.p12', 'p4ssw0rd', mode=RsaModes.PSS_MGF1_SHA3_256)
signature = private_key.sign('message')

# public_key = private_key.public_key
public_key = RsaPublicKey('fnmt.pem', mode=RsaModes.PSS_MGF1_SHA3_256)

ECDSA

from digsig import EcdsaPrivateKey, EcdsaModes

private_key = EcdsaPrivateKey('account.json', 'p4ssw0rd', mode=EcdsaModes.SECP256K1_SHA3_256)
signature = private_key.sign('message')

public_key = private_key.public_key

Verify signature

from digsig.errors import InvalidSignatureError

try:
    public_key.verify(signature)
except InvalidSignatureError:
    print('Invalid signature.')

Generate keys

RSA

from digsig import RsaPrivateKey, RsaModes

private_key = RsaPrivateKey(mode=RsaModes.PSS_MGF1_SHA256)
public_key = private_key.public_key

ECDSA

from digsig import EcdsaPrivateKey, EcdsaModes

private_key = EcdsaPrivateKey(mode=EcdsaModes.SECP256K1_KECCAK_256_ETHEREUM)
public_key = private_key.public_key

Export keys

RSA

private_pem = private_key.private_pem
public_pem = private_key.public_key.public_pem

ECDSA

private_value = private_key.private_value
private_value_bytes = private_key.private_value_bytes
private_value_hex = private_key.private_value_hex
private_value_base64 = private_key.private_value_base64
ethereum_keystore = private_key.get_ethereum_account()

public_value = private_key.public_key.public_value
public_bytes = private_key.public_key.public_bytes
public_base64 = private_key.public_key.public_base64
ethereum_address = private_key.public_key.ethereum_address

Supported modes

RSA

To-Do

ECDSA

To-Do

Supported formats

RSA

To-Do

ECDSA

To-Do

digsig's People

Contributors

brunneis avatar

Stargazers

 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.