Struct crypto_box::SecretKey
source · pub struct SecretKey { /* private fields */ }
Expand description
A crypto_box
secret key.
Implementations§
source§impl SecretKey
impl SecretKey
sourcepub fn from_bytes(bytes: [u8; 32]) -> Self
pub fn from_bytes(bytes: [u8; 32]) -> Self
Initialize SecretKey
from a byte array.
sourcepub fn from_slice(slice: &[u8]) -> Result<Self, TryFromSliceError>
pub fn from_slice(slice: &[u8]) -> Result<Self, TryFromSliceError>
Initialize SecretKey
from a byte slice.
Returns TryFromSliceError
if the slice length is not exactly equal
to KEY_SIZE
.
sourcepub fn generate(csprng: &mut impl CryptoRngCore) -> Self
Available on crate feature rand_core
only.
pub fn generate(csprng: &mut impl CryptoRngCore) -> Self
rand_core
only.Generate a random SecretKey
.
sourcepub fn public_key(&self) -> PublicKey
pub fn public_key(&self) -> PublicKey
sourcepub fn to_bytes(&self) -> [u8; 32]
pub fn to_bytes(&self) -> [u8; 32]
Serialize SecretKey
to bytes.
⚠️Warning
The serialized bytes are secret key material. Please treat them with the care they deserve!
Scalar
conversion notes
If you are using the From<Scalar>
impl on SecretKey
(as opposed
to using SecretKey::from_bytes
or one of the other methods that
decodes a secret key from bytes), this method will return the same
value as Scalar::to_bytes
, which may reflect “clamping” if it was
applied to the original Scalar
.
In such cases, it may be undesirable to call this method, since such a
value may not reflect the original scalar prior to clamping. We suggest
you don’t call this method when using From<Scalar>
unless you know
what you’re doing.
Calling SecretKey::to_scalar
can be used to safely round-trip the
scalar value in such cases.
Trait Implementations§
source§impl<'de> Deserialize<'de> for SecretKey
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for SecretKey
serde
only.