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
pub fn generate(csprng: &mut impl CryptoRngCore) -> Self
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.