diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-05-29 15:59:04 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-05-29 15:59:04 +0200 |
commit | fcf0bdf1bbccf72fe1f6315bf3156cc3970f362b (patch) | |
tree | 4b342204b1e32947bf66e6e04df3eea2661c3f5f /openpgp/examples | |
parent | bd94fc97de6911c447ab30e7b48a8e5d88bb4578 (diff) |
openpgp: Add asymmetric encryption example.
Diffstat (limited to 'openpgp/examples')
-rw-r--r-- | openpgp/examples/encrypt-for.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/openpgp/examples/encrypt-for.rs b/openpgp/examples/encrypt-for.rs new file mode 100644 index 00000000..8d704296 --- /dev/null +++ b/openpgp/examples/encrypt-for.rs @@ -0,0 +1,29 @@ +use std::env; +use std::io; + +extern crate openpgp; +use openpgp::armor; +use openpgp::serialize::stream::{ + wrap, LiteralWriter, Encryptor, EncryptionMode, +}; + +fn main() { + let args: Vec<String> = env::args().collect(); + if args.len() != 2 { + panic!("A simple encryption filter.\n\n\ + Usage: {} <keyfile> <input >output\n", args[0]); + } + + let keyfile = &args[1]; + let tpk = openpgp::TPK::from_reader( + openpgp::Reader::from_file(keyfile).expect("Failed to open file")) + .expect("Failed to read key"); + let sink = armor::Writer::new(io::stdout(), armor::Kind::Message); + let encryptor = Encryptor::new(wrap(sink), &[], &[&tpk], + EncryptionMode::AtRest) + .expect("Failed to create encryptor"); + let mut literal_writer = LiteralWriter::new(encryptor, 't', None, 0) + .expect("Failed to create literal writer"); + io::copy(&mut io::stdin(), &mut literal_writer) + .expect("Failed to encrypt"); +} |