An open API service indexing awesome lists of open source software.

https://github.com/labteral/digsig

Digital Signature Toolkit for Python
https://github.com/labteral/digsig

digital-signature fmnt p12 pfx pkcs12 rsa

Last synced: about 2 months ago
JSON representation

Digital Signature Toolkit for Python

Awesome Lists containing this project

README

        


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
```bash
pip install digsig
```

# Load keys
## Automatic detection
RSA (X.509)
```python
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)
```python
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
```python
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
```python
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
```python
from digsig.errors import InvalidSignatureError

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

# Generate keys
## RSA
```python
from digsig import RsaPrivateKey, RsaModes

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

## ECDSA
```python
from digsig import EcdsaPrivateKey, EcdsaModes

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

# Export keys
## RSA
```python
private_pem = private_key.private_pem
public_pem = private_key.public_key.public_pem
```

## ECDSA
```python
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