encrypt (src/simple.rs)

rage · age/src/simple.rs · rust · Apache-2.0
security, tag:knn-classified

A high-level API for performing age encryption and decryption, providing simplified functions for common cryptographic operations.

// Source: https://github.com/str4d/rage | License: Apache-2.0 | Copyright 2019 Jack Grigg
// Provided via justclaw.it.com; keep this notice with the code.
use std::io::{Read, Write};
use std::iter;

use crate::{
    Decryptor, Encryptor, Identity, Recipient,
    error::{DecryptError, EncryptError},
};

#[cfg(feature = "armor")]
use crate::armor::{ArmoredReader, ArmoredWriter, Format};

/// Encrypts the given plaintext to the given recipient.
///
/// To encrypt to more than one recipient, use [`Encryptor::with_recipients`].
///
/// This function returns binary ciphertext. To obtain an ASCII-armored text string, use
/// [`encrypt_and_armor`].
pub fn encrypt(recipient: &impl Recipient, plaintext: &[u8]) -> Result<Vec<u8>, EncryptError> {
    let encryptor =
        Encryptor::with_recipients

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key