pynacl
pynacl copied to clipboard
Signature example
Hi,
I found the following non-deterministic ed25519 signature code in a deprecated library.
import ed25519
privKey, pubKey = ed25519.create_keypair()
print("Private key (32 bytes):", privKey.to_ascii(encoding='hex'))
print("Public key (32 bytes): ", pubKey.to_ascii(encoding='hex'))
msg = b'Message for Ed25519 signing'
signature = privKey.sign(msg, encoding='hex')
print("Signature (64 bytes):", signature)
try:
pubKey.verify(signature, msg, encoding='hex')
print("The signature is valid.")
except:
print("Invalid signature!")
I then pip installed PyNaCl successfully. I then followed your documentation, from where I got
from PyNaCl.signing import SigningKey
# Generate a new random signing key
signing_key = SigningKey.generate()
# Sign a message with the signing key
signed = signing_key.sign(b"Attack at Dawn")
# Obtain the verify key for a given signing key
verify_key = signing_key.verify_key
# Serialize the verify key to send it to a third party
verify_key_bytes = verify_key.encode()
with either PyNaCl or nacl or NaCl (I tried them all). The result is:
> python .\example_signature_edwards.py
Traceback (most recent call last):
File "C:\Users\UserName\Desktop\NewPyEnv\example_signature_edwards.py", line 1, in <module>
from PyNaCl.signing import SigningKey
ModuleNotFoundError: No module named 'PyNaCl'
Can you provide a minimum working example? I apologize in advance for my apparent inability to get smart of these documentations that I find all around. Some are uselessly elaborate without giving an actual working example and others are too short, still without giving an actual working example; and again others give working examples that are impossible to understand for someone with a novice math crypto background. Who is the audience?
The library is imported as nacl
, not PyNaCl
.