pub struct SecretKey(/* private fields */);Expand description
A secret key for Ed25519 digital signatures
Used to create signatures that can be verified with the corresponding PublicKey.
The secret key must be kept private to maintain security.
§Properties
- Size: 64 bytes (512 bits)
- Contains both the secret scalar (32 bytes) and the public key (32 bytes)
- Must be kept confidential
- Used to sign messages
§Security Considerations
The secret key is the most sensitive component in the digital signature system. If compromised, an attacker can create valid signatures for any message, impersonating the legitimate owner of the key.
Best practices for secret key management:
- Store secret keys in secure, encrypted storage
- Consider using hardware security modules (HSMs) for high-security applications
- Implement proper access controls to limit who can use the signing key
- Rotate keys periodically according to your security policy
- Have a revocation plan in case a key is compromised
§Usage
use libsodium_rs as sodium;
use sodium::crypto_sign;
use sodium::ensure_init;
// Initialize libsodium
ensure_init().expect("Failed to initialize libsodium");
// Generate a key pair
let keypair = crypto_sign::KeyPair::generate().unwrap();
let secret_key = keypair.secret_key;
// Sign a message
let message = b"Important document";
let signature = crypto_sign::sign_detached(message, &secret_key).unwrap();
// In a real application, you would securely store the secret key
// and implement proper key management proceduresImplementations§
Trait Implementations§
impl Eq for SecretKey
impl StructuralPartialEq for SecretKey
Auto Trait Implementations§
impl Freeze for SecretKey
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin for SecretKey
impl UnsafeUnpin for SecretKey
impl UnwindSafe for SecretKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more