[−][src]Crate age
Library for encrypting and decryping age messages
age is a simple, secure, and modern encryption tool with small explicit keys, no config options, and UNIX-style composability.
All crate versions prior to 1.0 are beta releases for testing purposes. The age specification is available here.
Examples
Key-based encryption
use std::io::{Read, Write}; let key = age::SecretKey::generate(); let pubkey = key.to_public(); let plaintext = b"Hello world!"; let encryptor = age::Encryptor::Keys(vec![pubkey]); let mut encrypted = vec![]; { let mut writer = encryptor.wrap_output(&mut encrypted, false)?; writer.write_all(plaintext)?; writer.finish()?; }; let decryptor = age::Decryptor::Keys(vec![key.into()]); let mut reader = decryptor.trial_decrypt(&encrypted[..], |_| None)?; let mut decrypted = vec![]; reader.read_to_end(&mut decrypted); assert_eq!(decrypted, plaintext);
Passphrase-based encryption
use secrecy::Secret; use std::io::{Read, Write}; let plaintext = b"Hello world!"; let passphrase = "this is not a good passphrase"; let encryptor = age::Encryptor::Passphrase(Secret::new(passphrase.to_owned())); let mut encrypted = vec![]; { let mut writer = encryptor.wrap_output(&mut encrypted, false)?; writer.write_all(plaintext)?; writer.finish()?; }; let decryptor = age::Decryptor::Passphrase(Secret::new(passphrase.to_owned())); let mut reader = decryptor.trial_decrypt(&encrypted[..], |_| None)?; let mut decrypted = vec![]; reader.read_to_end(&mut decrypted); assert_eq!(decrypted, plaintext);
Re-exports
pub use keys::SecretKey; |
Modules
cli_common | Common helpers for CLI binaries. |
keys | Key structs and serialization. |
Structs
StreamReader | Provides access to a decrypted age message. |
Enums
Decryptor | Handles the various types of age decryption. |
Encryptor | Handles the various types of age encryption. |
Error | The various errors that can be returned during the decryption process. |