Code Monkey home page Code Monkey logo

simplestcrypt's Introduction

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

simplestcrypt's People

Contributors

totalkrill avatar

Watchers

James Cloos avatar  avatar

simplestcrypt's Issues

Serializing / Deserializing with bincode may make results incompatible with other libraries.

I'm using this library and making the results interact with javascript code using https://github.com/miscreant/miscreant.js/

I would expect a serialized nonce+ciphertext to look like:
(16 bytes for the nonce) + (rest of bytes for ciphertext)

But bincode just adds 8 bytes in between so it looks like:
(16 bytes for the nonce + 8 bytes with size of the Vec + (rest of bytes for Vec ciphertext).

These extra 8 bytes make the serialized ciphertext be incompatible with miscreant, and maybe other libraries, so they have to be taken into account.

I know serialization is not part of the standard so there are no rights or wrongs, but the serialization used before converting to hex is specific to rust, so it may be worth mentioning in the readme if someone else runs into this.

Best!

edit: I looked into bincode to see what the extra 8 bytes were.

Upgrade the rand version

Please update the version requirements to support the latest rand crate. At the time of this writing it was 0.8.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.