pub struct Ed25519SecretKey(/* private fields */);
Expand description
An Ed25519 secret key, used to create digital signatures.
Implementations§
Source§impl Ed25519SecretKey
impl Ed25519SecretKey
Sourcepub fn to_bytes(&self) -> Box<[u8; 32]>
pub fn to_bytes(&self) -> Box<[u8; 32]>
Get the byte representation of the secret key.
Warning: This creates a copy of the key which won’t be zeroized, the caller of the method needs to make sure to zeroize the returned array.
Sourcepub fn from_slice(bytes: &[u8; 32]) -> Self
pub fn from_slice(bytes: &[u8; 32]) -> Self
Try to create a Ed25519SecretKey
from a slice of bytes.
Sourcepub fn to_base64(&self) -> String
pub fn to_base64(&self) -> String
Convert the secret key to a base64 encoded string.
This can be useful if the secret key needs to be sent over the network or persisted.
Warning: The string should be zeroized after it has been used, otherwise an unintentional copy of the key might exist in memory.
Sourcepub fn from_base64(input: &str) -> Result<Self, KeyError>
pub fn from_base64(input: &str) -> Result<Self, KeyError>
Try to create a Ed25519SecretKey
from a base64 encoded string.
Sourcepub fn public_key(&self) -> Ed25519PublicKey
pub fn public_key(&self) -> Ed25519PublicKey
Get the public key that matches this Ed25519SecretKey
.
Sourcepub fn sign(&self, message: &[u8]) -> Ed25519Signature
pub fn sign(&self, message: &[u8]) -> Ed25519Signature
Sign the given slice of bytes with this Ed25519SecretKey
.
The signature can be verified using the public key.
§Examples
use vodozemac::{Ed25519SecretKey, Ed25519PublicKey};
let secret = Ed25519SecretKey::new();
let message = "It's dangerous to go alone";
let signature = secret.sign(message.as_bytes());
let public_key = secret.public_key();
public_key.verify(message.as_bytes(), &signature).expect("The signature has to be valid");