serde-encrypt
:closed_lock_with_key: Encrypts all the Serialize.
Alice Bob
+-----------------------------------+ +-----------------------------------+
| #[derive(Serialize, Deserialize)] | | #[derive(Serialize, Deserialize)] |
| struct Message {} | | struct Message {} |
+-----------------------------------+ +-----------------------------------+
| .encrypt() ^
v | ::decrypt()
+-----------------------------------+ +-----------------------------------+
| struct EncryptedMessage | | struct EncryptedMessage |
+-----------------------------------+ +-----------------------------------+
| .serialize() ^
v | ::deserialize()
+-----------------------------------+ +-----------------------------------+
| struct Vec<u8> | -----> | struct Vec<u8> |
+-----------------------------------+ +-----------------------------------+
Overview
serde-encrypt encrypts/decrypts any strcts and enums that implements serde::{Serialize, Deserialize}.
serde-encrypt supports both shared-key encryption (XChaCha20Poly1305) and public-key encryption (X25519XChaCha20Poly1305), both of which are considered to be secure enough.
serde-encrypt is optionally available in no_std environments.
[]
= "(version)" # If you use std
= { = "(version)", = false} # If you need no_std
Example
If you and your peer already have shared-key, just implement SerdeEncryptSharedKey trait to your Serialize and Deserialize data types.
Then, you can serialize the Message into Vec<u8> in encrypted form.
let shared_key = ; // or read from your filesystem?
let msg = Message ;
let encrypted_message = msg.encrypt?;
let serialized_encrypted_message: = encrypted_message.serialize?;
After your peer gets the binary, he or she can decrypt and deserialize it to Message.
let shared_key = ; // or your peer reads from filesystem?
let encrypted_message = deserialize?;
let msg = decrypt_owned
Further examples...
- :eyes: Encrypts struct with reference fields
- :key: Generates shared-key and safely exchange it to your peer. And then, encrypt/decrypt messages using the shared-key.
- :books: Encrypts/Decrypts complex serde types
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in serde-encrypt by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.