ECDSA Cryptographic Signature Library

0.19.2 · active · verified Sun Mar 29

ecdsa is a pure Python implementation of Elliptic Curve Cryptography (ECC) supporting ECDSA (Elliptic Curve Digital Signature Algorithm), EdDSA (Edwards-curve Digital Signature Algorithm), and ECDH (Elliptic Curve Diffie-Hellman). It is actively maintained with several releases per year, providing a robust solution for digital signatures in Python applications. The current version is 0.19.2.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to generate an ECDSA private and public key pair using the NIST256p curve, sign a message digest with the private key, and then verify the signature using the corresponding public key.

import hashlib
from ecdsa import SigningKey, NIST256p, VerifyingKey

# 1. Generate a private key using the NIST256p curve
sk = SigningKey.generate(curve=NIST256p)
print("Private Key (hex):", sk.to_string().hex())

# 2. Derive the public key
vk = sk.get_verifying_key()
print("Public Key (hex):", vk.to_string().hex())

# 3. Message to sign (must be bytes)
message = b"This is a test message to be signed."

# Hash the message before signing
message_hash = hashlib.sha256(message).digest()

# 4. Sign the message hash
signature = sk.sign_digest(message_hash)
print("Signature (hex):", signature.hex())

# 5. Verify the signature
try:
    assert vk.verify_digest(signature, message_hash) == True
    print("Signature is valid.")
except Exception as e:
    print(f"Signature verification failed: {e}")

view raw JSON →