Add example that prints generated keys
This commit is contained in:
parent
7e44a2be9b
commit
f491286068
25
examples/generate.rs
Normal file
25
examples/generate.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use failure::Error;
|
||||
use rsa::RSAPrivateKey;
|
||||
use rsa_pem::KeyExt;
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let key = RSAPrivateKey::new(&mut rng, 2048)?;
|
||||
|
||||
println!("PKCS1 - Private");
|
||||
println!("{}", key.to_pem_pkcs1()?);
|
||||
println!();
|
||||
println!("PKCS8 - Private");
|
||||
println!("{}", key.to_pem_pkcs8()?);
|
||||
|
||||
let key = key.to_public_key();
|
||||
|
||||
println!("PKCS1 - Public");
|
||||
println!("{}", key.to_pem_pkcs1()?);
|
||||
println!();
|
||||
println!("PKCS8 - Public");
|
||||
println!("{}", key.to_pem_pkcs8()?);
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in a new issue