pub struct StreamKey { /* private fields */ }Expand description
Stream Key that allows encrypting data into a Lockbox and decrypting it later.
This acts as a wrapper for a specific cryptographic symmetric key, which can only be used with the corresponding symmetric encryption algorithm. The underlying key may be located in a hardware module or some other private keystore; in this case, it may be impossible to export the key.
// Make a new temporary key
let key = StreamKey::new();
let id = key.id().clone();
// Encrypt some data with the key, then turn it into a byte vector
let data = b"I am sensitive information, about to be encrypted";
let lockbox = key.encrypt_data(data.as_ref());
let mut encoded = Vec::new();
encoded.extend_from_slice(lockbox.as_bytes());
// Decrypt that data with the same key
let dec_lockbox = DataLockboxRef::from_bytes(encoded.as_ref())?;
let dec_data = key.decrypt_data(dec_lockbox)?;Implementations§
Source§impl StreamKey
impl StreamKey
Sourcepub fn from_interface(interface: Arc<dyn StreamInterface>) -> Self
pub fn from_interface(interface: Arc<dyn StreamInterface>) -> Self
Create a new StreamKey to hold a StreamInterface implementation. Can be used by
implementors of a vault when making new StreamKey instances.
Sourcepub fn with_rng<R>(csprng: &mut R) -> StreamKey
pub fn with_rng<R>(csprng: &mut R) -> StreamKey
Generate a temporary StreamKey that exists only in program memory,
using the provided cryptographic RNG.
Sourcepub fn with_rng_and_version<R>(
csprng: &mut R,
version: u8,
) -> Result<StreamKey, CryptoError>
pub fn with_rng_and_version<R>( csprng: &mut R, version: u8, ) -> Result<StreamKey, CryptoError>
Generate a temporary StreamKey that exists only in program memory. Uses the specified
version instead of the default, and fails if the version is unsupported.
Sourcepub fn encrypt_data(&self, content: &[u8]) -> DataLockbox
pub fn encrypt_data(&self, content: &[u8]) -> DataLockbox
Encrypt a byte slice into a DataLockbox.
Sourcepub fn encrypt_data_with_rng<R: CryptoRng + RngCore>(
&self,
csprng: &mut R,
content: &[u8],
) -> DataLockbox
pub fn encrypt_data_with_rng<R: CryptoRng + RngCore>( &self, csprng: &mut R, content: &[u8], ) -> DataLockbox
Encrypt a byte slice into a DataLockbox. Requires a cryptographic RNG to generate the
needed nonce.
Sourcepub fn decrypt_lock_key(
&self,
lockbox: &LockLockboxRef,
) -> Result<LockKey, CryptoError>
pub fn decrypt_lock_key( &self, lockbox: &LockLockboxRef, ) -> Result<LockKey, CryptoError>
Attempt to decrypt a LockLockboxRef with this key. On success, the returned LockKey is
temporary and not associated with any Vault.
Sourcepub fn decrypt_identity_key(
&self,
lockbox: &IdentityLockboxRef,
) -> Result<IdentityKey, CryptoError>
pub fn decrypt_identity_key( &self, lockbox: &IdentityLockboxRef, ) -> Result<IdentityKey, CryptoError>
Attempt to decrypt a IdentityLockboxRef with this key. On success, the returned
IdentityKey is temporary and not associated with any Vault.
Sourcepub fn decrypt_stream_key(
&self,
lockbox: &StreamLockboxRef,
) -> Result<StreamKey, CryptoError>
pub fn decrypt_stream_key( &self, lockbox: &StreamLockboxRef, ) -> Result<StreamKey, CryptoError>
Attempt to decrypt a StreamLockboxRef with this key. On success, the returned
StreamKey is temporary and not associated with any Vault.
Sourcepub fn decrypt_data(
&self,
lockbox: &DataLockboxRef,
) -> Result<Vec<u8>, CryptoError>
pub fn decrypt_data( &self, lockbox: &DataLockboxRef, ) -> Result<Vec<u8>, CryptoError>
Attempt to decrypt a DataLockboxRef with this key.
Sourcepub fn export_for_lock(&self, lock: &LockId) -> Option<StreamLockbox>
pub fn export_for_lock(&self, lock: &LockId) -> Option<StreamLockbox>
Pack this secret into a StreamLockbox, meant for the recipient specified by id. Returns
None if this key cannot be exported.
Sourcepub fn export_for_lock_with_rng<R: CryptoRng + RngCore>(
&self,
csprng: &mut R,
lock: &LockId,
) -> Option<StreamLockbox>
pub fn export_for_lock_with_rng<R: CryptoRng + RngCore>( &self, csprng: &mut R, lock: &LockId, ) -> Option<StreamLockbox>
Pack this secret into a StreamLockbox, meant for the recipient specified by id. Returns
None if this key cannot be exported.
Sourcepub fn export_for_stream(&self, stream: &StreamKey) -> Option<StreamLockbox>
pub fn export_for_stream(&self, stream: &StreamKey) -> Option<StreamLockbox>
Pack this key into a StreamLockbox, meant for the recipient specified by stream. Returns
None if this key cannot be exported for the given recipient. Generally, the recipient
should be in the same Vault as the key being exported, or the exported key should be a
temporary key.
Sourcepub fn export_for_stream_with_rng<R: CryptoRng + RngCore>(
&self,
csprng: &mut R,
stream: &StreamKey,
) -> Option<StreamLockbox>
pub fn export_for_stream_with_rng<R: CryptoRng + RngCore>( &self, csprng: &mut R, stream: &StreamKey, ) -> Option<StreamLockbox>
Pack this key into a StreamLockbox, meant for the recipient specified by stream. Returns
None if this key cannot be exported for the given recipient. Generally, the recipient
should be in the same Vault as the key being exported, or the exported key should be a
temporary key.