Skip to main content

encrypt_bytes

Function encrypt_bytes 

Source
pub fn encrypt_bytes(plaintext: &[u8]) -> Result<String, CryptoError>
Expand description

Encrypt raw bytes and return a versioned ASCII ciphertext string.

Output format:

  • v1:nonce_b64:ciphertext_b64

Where:

  • nonce_b64 is 12 random bytes (URL-safe base64, no padding)
  • ciphertext_b64 includes the GCM authentication tag

§Key behavior

This function auto-initializes the master key if missing (first run).

§Example

use keycrypt::{encrypt_bytes, decrypt_bytes};

let enc = encrypt_bytes(b"hello")?;
let dec = decrypt_bytes(&enc)?;
assert_eq!(dec.as_slice(), b"hello");

§Errors