Crate ed25519_dalek [−] [src]
ed25519 signatures and verification
Example
Creating an ed25519 signature on a message is simple.
First, we need to generate a Keypair
, which includes both public
and secret halves of an asymmetric key. To do so, we need a
cryptographically secure random number generator (CSPRING). For
this example, we'll use the operating system's builtin PRNG to
generate a keypair:
extern crate rand; extern crate ed25519; use rand::Rng; use rand::OsRng; use ed25519::Keypair; let mut cspring: OsRng = OsRng::new().unwrap(); let keypair: Keypair = Keypair::generate(&mut cspring);
We can now use this keypair
to sign a message:
let message: &[u8] = "This is a test of the tsunami alert system.".as_bytes(); let signature: Signature = keypair.sign(message);
As well as to verify that this is, indeed, a valid signature on
that message
:
let verified: bool = keypair.verify(message, &signature); assert!(verified);
Anyone else, given the public
half of the keypair
can also easily
verify this signature:
let public_key: PublicKey = keypair.public; let verified: bool = public_key.verify(message, &signature); assert!(verified);
Structs
Keypair |
An ed25519 keypair. |
PublicKey |
An ed25519 public key. |
SecretKey |
An ed25519 private key. |
Signature |
An ed25519 signature. |