#data-transfer #encryption #encryption-key #symmetric-encryption

simplestcrypt

Simplest way to perform a symmetric encryption, using a preshared key. Very small wrapper around aes-siv crate, with randomly generated nonces, for anything more advanced, use aes-siv instead

5 releases

0.1.4 Aug 21, 2024
0.1.3 Mar 24, 2022
0.1.2 Nov 19, 2020
0.1.1 Nov 18, 2020
0.1.0 Nov 18, 2020

#1125 in Cryptography

Download history 7/week @ 2024-07-17 43/week @ 2024-07-24 17/week @ 2024-07-31 1/week @ 2024-08-07 137/week @ 2024-08-21 5/week @ 2024-08-28 8/week @ 2024-09-04 32/week @ 2024-09-11 27/week @ 2024-09-18 55/week @ 2024-09-25 69/week @ 2024-10-02 21/week @ 2024-10-09

174 downloads per month

MIT license

8KB
77 lines

simplestcrypt

Simplest way to perform a symmetric encryption, using a preshared key. Very small wrapper around aes-siv crate, with randomly generated nonces, for anything more advanced, use aes-siv instead

Example

use std::str;
fn main() {
    let payload = "Hello world!".as_bytes();
    let password = b"hello wooooooooo";

    let encrypted = simplestcrypt::encrypt_and_serialize(&password[..], &payload).unwrap();
    let plain = simplestcrypt::deserialize_and_decrypt(&password[..], &encrypted).unwrap();

    println!("{:?}", str::from_utf8(&plain));
}

Serialization notes

Bincode adds 8 bytes in between the serialized nonce and the serialized ciphertext so it looks like:

Bytes Description
0 - 15 Nonce used when encrypting the ciphertext
16 - 23 The lenght of the cyphertext
24 - .. Cyphertext

This needs to be taken into account when interoperating with other libraries

Dependencies

~1.5–2.3MB
~49K SLoC