Skip to content

labteral/digsig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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