pub trait SerdeEncryptSharedKey {
    type S: TypedSerialized<T = Self>;

    fn encrypt(&self, shared_key: &SharedKey) -> Result<EncryptedMessage, Error>
    where
        Self: Serialize
, { ... } fn decrypt_owned(
        encrypted_message: &EncryptedMessage,
        shared_key: &SharedKey
    ) -> Result<Self, Error>
    where
        Self: DeserializeOwned
, { ... } fn decrypt_ref<'de>(
        encrypted_message: &EncryptedMessage,
        shared_key: &SharedKey
    ) -> Result<Self::S, Error>
    where
        Self: Deserialize<'de>
, { ... } }
Expand description

Shared-key authenticated encryption for serde-serializable types.

Features

  • Message authentication.
  • Different cipher-text for the same plain-text to avoid attacks such as statistical analysis of cipher-text.
  • Uses small (32-byte) key.

Anti-features

  • Identity authentication of sender nor receiver.

Good for both large and small message encryption / decryption.

when sender and receiver does not hold shared key yet:

First, message sender or receiver should generate SharedKey.

And then sender or receiver who generated the key should give it to another using safe communication. SerdeEncryptPublicKey is recommended for it.

Examples

Encrypting owned data with already-shared key

See this example.

Generate and exchange shared key and encrypt struct with reference fields

See this example.

Algorithm

  • Encryption: XChaCha20
  • Message authentication: Poly1305 MAC

Required Associated Types

Serializer implementation

Provided Methods

Serialize and encrypt.

Failures

Decrypt and deserialize into DeserializeOwned type.

Failures

Just decrypts cipher-text. Returned data must be deserialized later. Types implementing serde::Deserialize<'de> (not serde::de::DeserializeOwned) should use this function to resolve lifetime.

Failures

Implementors