Serde-encrypt: A Rust crate to encrypt any serializable data
I&#x27;m developing a Rust crate serde-encrypt (https:&#x2F;&#x2F;github.com&#x2F;laysakura&#x2F;serde-encrypt).
It provides handy traits to give encryption&#x2F;decryption power to any structs&#x2F;enums that implements serde::{Serialize, Deserialize}.<p>It is available not only std environment but also no_std. Also Intel SGX is supported.
If you feel interested, visit my repository to see other examples, check algorithms used, and give a star<p>-------------------------<p>#[derive(Debug, Serialize, Deserialize)]<p>struct Message {<p><pre><code>    content: String,

    sender: String,
</code></pre>
}<p>&#x2F;&#x2F; This is the trick!<p>impl SerdeEncryptSharedKey for Message {}<p>let shared_key = [0u8; 32];  &#x2F;&#x2F; or read from your filesystem?<p>let msg = Message {<p><pre><code>    content: &quot;I  you.&quot;.to_string(),

    sender: &quot;Alice&quot;.to_string(),
</code></pre>
};<p>&#x2F;&#x2F; Encrypt and serialize the serde struct<p>let encrypted_message = msg.encrypt(&amp;shared_key)?;<p>let serialized_encrypted_message: Vec&lt;u8&gt; = encrypted_message.serialize()?;<p>&#x2F;&#x2F; Deserialize and decrypt<p>let encrypted_message = EncryptedMessage::deserialize(serialized_encrypted_message)?;<p>let msg = Message::decrypt_owned(&amp;encrypted_message, &amp;shared_key)<p>-------------------------<p>SerdeEncryptPublicKey trait is also provided mainly for secure shared-key exchange (using ECDH algorithm internally).