LightDSA

0.0.3 · abandoned · verified Fri Apr 17

LightDSA (version 0.0.3) is a lightweight Python library providing Digital Signature Algorithm functionalities. Currently, it primarily supports the RSA algorithm for generating keys, signing data, and verifying signatures. Its development appears to be inactive since 2021, and new releases are infrequent.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to generate RSA keys, sign a message, and verify the signature using the `LightDSA` class. It also shows how to load keys from PEM format.

from lightdsa import LightDSA

# 1. Generate keys
# For RSA, key_size must be between 1024 and 4096 (inclusive)
# and a multiple of 256.
dsa = LightDSA(key_size=2048) # Default is 2048
private_key_pem = dsa.private_key_to_pem().decode('utf-8')
public_key_pem = dsa.public_key_to_pem().decode('utf-8')

print("Private Key (PEM format):")
print(private_key_pem)
print("\nPublic Key (PEM format):")
print(public_key_pem)

# 2. Sign data
message_to_sign = "This is a secret message."
signature = dsa.sign(message_to_sign.encode('utf-8'))

print(f"\nMessage: {message_to_sign}")
print(f"Signature: {signature.hex()}")

# 3. Verify signature using the current object's keys
is_valid = dsa.verify(message_to_sign.encode('utf-8'), signature)
print(f"Signature valid: {is_valid}")

# You can also load keys from PEM strings into a new LightDSA instance
dsa_loaded = LightDSA(key_size=2048) # key_size required for initialization
dsa_loaded.load_public_key_from_pem(public_key_pem.encode('utf-8'))
dsa_loaded.load_private_key_from_pem(private_key_pem.encode('utf-8')) # Optional for verification

is_valid_loaded = dsa_loaded.verify(message_to_sign.encode('utf-8'), signature)
print(f"Signature valid (loaded keys): {is_valid_loaded}")

view raw JSON →