Digital Signatures (original) (raw)

NOTE: if all you need are Ed25519 digital signatures, consider theed25519 geminstead which does not require libsodium as a dependency but still works on CRuby and JRuby

In the real world, signatures help uniquely identify people because everyone's signature is unique. Digital signatures work similarly in that they are unique to holders of a private key, but unlike real world signatures, digital signatures are unforgable.

Digital signatures allow you to publish a public key, then you can use your private signing key to sign messages. Others who have your public key can then use it to validate that your messages are actually authentic.

Code Example

Signer's perspective (RbNaCl::SigningKey):

Generate a new random signing key

signing_key = RbNaCl::SigningKey.generate

Serialize key to bytestring - load using RbNaCl::SigningKey.new(bytes)

signing_key.to_s

Sign a message with the signing key

signature = signing_key.sign(message)

Obtain the verify key for a given signing key

verify_key = signing_key.verify_key

Convert the verify key to a string to send it to a third party

verify_key.to_s

Verifier's perspective (RbNaCl::VerifyKey):

Create a VerifyKey object from a public key

verify_key = RbNaCl::VerifyKey.new(verify_key)

Check the validity of a message's signature

Will raise RbNaCl::BadSignatureError if the signature check fails

verify_key.verify(signature, message)

Algorithm features:

Algorithm details:

Algorithm diagram (Ed25519):

Ed25519 Diagram

RDoc