We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regarding ECDSA, I found this to work for the latest release of pycoin:
https://cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-examples#ecdsa-sign-verify-using-the-secp-256-k1-curve-and-sha-3-256
from pycoin.ecdsa.secp256k1 import secp256k1_generator import hashlib, secrets
def sha3_256Hash(msg): hashBytes = hashlib.sha3_256(msg.encode("utf8")).digest() print(f'msgHash={hashBytes.hex()}') return int.from_bytes(hashBytes, byteorder="big")
def signECDSAsecp256k1(msg, privKey): msgHash = sha3_256Hash(msg) signature = secp256k1_generator.sign(privKey, msgHash) return signature
def verifyECDSAsecp256k1(msg, signature, pubKey): msgHash = sha3_256Hash(msg) valid = secp256k1_generator.verify(pubKey, msgHash, signature) return valid
msg = "Message for ECDSA signing" privKey = secrets.randbelow(secp256k1_generator.order()) signature = signECDSAsecp256k1(msg, privKey) print("Message:", msg) print("Private key:", hex(privKey)) print("Signature: r=" + hex(signature[0]) + ", s=" + hex(signature[1]))
pubKey = secp256k1_generator * privKey valid = verifyECDSAsecp256k1(msg, signature, pubKey) print("\nMessage:", msg) print("Public key: (" + hex(pubKey[0]) + ", " + hex(pubKey[1]) + ")") print("Signature valid?", valid)
msg = "Tampered message" valid = verifyECDSAsecp256k1(msg, signature, pubKey) print("\nMessage:", msg) print("Signature (tampered msg) valid?", valid)
Cheers!
Mark von der Lieth
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Regarding ECDSA, I found this to work for the latest release of pycoin:
https://cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-examples#ecdsa-sign-verify-using-the-secp-256-k1-curve-and-sha-3-256
from pycoin.ecdsa.secp256k1 import secp256k1_generator
import hashlib, secrets
def sha3_256Hash(msg):
hashBytes = hashlib.sha3_256(msg.encode("utf8")).digest()
print(f'msgHash={hashBytes.hex()}')
return int.from_bytes(hashBytes, byteorder="big")
def signECDSAsecp256k1(msg, privKey):
msgHash = sha3_256Hash(msg)
signature = secp256k1_generator.sign(privKey, msgHash)
return signature
def verifyECDSAsecp256k1(msg, signature, pubKey):
msgHash = sha3_256Hash(msg)
valid = secp256k1_generator.verify(pubKey, msgHash, signature)
return valid
ECDSA sign message (using the curve secp256k1 + SHA3-256)
msg = "Message for ECDSA signing"
privKey = secrets.randbelow(secp256k1_generator.order())
signature = signECDSAsecp256k1(msg, privKey)
print("Message:", msg)
print("Private key:", hex(privKey))
print("Signature: r=" + hex(signature[0]) + ", s=" + hex(signature[1]))
ECDSA verify signature (using the curve secp256k1 + SHA3-256)
pubKey = secp256k1_generator * privKey
valid = verifyECDSAsecp256k1(msg, signature, pubKey)
print("\nMessage:", msg)
print("Public key: (" + hex(pubKey[0]) + ", " + hex(pubKey[1]) + ")")
print("Signature valid?", valid)
ECDSA verify tampered signature (using the curve secp256k1 + SHA3-256)
msg = "Tampered message"
valid = verifyECDSAsecp256k1(msg, signature, pubKey)
print("\nMessage:", msg)
print("Signature (tampered msg) valid?", valid)
Cheers!
Mark von der Lieth
The text was updated successfully, but these errors were encountered: