VibeProtocol 0.1.0

Vibe Protocol is a secure, decentralized, and privacy-focused messaging protocol. Its designed using Sodium, Base64, and other cryptographic libraries to ensure the highest level of security and privacy.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use sodiumoxide::crypto::{secretbox, box_};
use sodiumoxide::init as sodium_init;

pub fn encrypt_sodium(plaintext: &str) -> Result<(Vec<u8>, secretbox::Nonce, secretbox::Key), String> {
    sodium_init().map_err(|_| "Failed to initialize sodiumoxide")?;

    let key = secretbox::gen_key();
    let nonce = secretbox::gen_nonce();
    let ciphertext = secretbox::seal(plaintext.as_bytes(), &nonce, &key);

    Ok((ciphertext, nonce, key))
}

pub fn decrypt_sodium(ciphertext: &[u8], nonce: &secretbox::Nonce, key: &secretbox::Key) -> Result<String, String> {
    secretbox::open(ciphertext, nonce, key)
        .map(|decrypted| String::from_utf8(decrypted).unwrap_or_else(|_| "Failed to decode plaintext".to_owned()))
        .map_err(|_| "Decryption failed".to_owned())
}