Module std::crypto::encrypt

Symmetric encryption and decryption.

Encrypt and decrypt data using AES-256-GCM.

Examples

import std::crypto::encrypt;

fn main() {
    let key = crypto.random_bytes(32);
    let ciphertext = encrypt.seal(key, "hello world");
    let plaintext = encrypt.open(key, ciphertext);
    println(plaintext);
}

Contents

Functions

Function seal

pub fn seal(key: bytes, plaintext: String) -> bytes

Encrypt plaintext using AES-256-GCM with the given key.

Returns the ciphertext (nonce + encrypted data) as bytes.

Function open

pub fn open(key: bytes, ciphertext: bytes) -> String

Decrypt ciphertext using AES-256-GCM with the given key.

Returns the decrypted plaintext string.