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
- Host: GitHub
- URL: https://github.com/labteral/digsig
- Owner: labteral
- License: gpl-3.0
- Created: 2021-02-11T15:59:54.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-06-28T14:28:15.000Z (almost 4 years ago)
- Last Synced: 2025-03-11T01:52:02.391Z (2 months ago)
- Topics: digital-signature, fmnt, p12, pfx, pkcs12, rsa
- Language: Python
- Homepage: https://pypi.org/project/digsig/
- Size: 53.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
DigSig
Digital signatures with PythonThe 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, PublicKeyprivate_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, PublicKeyprivate_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, RsaFormatsprivate_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, EcdsaModesprivate_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 InvalidSignatureErrortry:
public_key.verify(signature)
except InvalidSignatureError:
print('Invalid signature.')
```# Generate keys
## RSA
```python
from digsig import RsaPrivateKey, RsaModesprivate_key = RsaPrivateKey(mode=RsaModes.PSS_MGF1_SHA256)
public_key = private_key.public_key
```## ECDSA
```python
from digsig import EcdsaPrivateKey, EcdsaModesprivate_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