pub fn create_key(
password: &str,
user_ids: &[&str],
cipher: CipherSuite,
creation_time: Option<DateTime<Utc>>,
expiration_time: Option<DateTime<Utc>>,
subkeys_expiration: Option<DateTime<Utc>>,
which_keys: SubkeyFlags,
can_primary_sign: bool,
can_primary_expire: bool,
) -> Result<GeneratedKey>Expand description
Generate a new OpenPGP key pair.
§Arguments
password- Password to protect the secret keyuser_ids- List of user IDs (e.g., “Name email@example.com”)cipher- Cipher suite to use (seeCipherSuitefor options)creation_time- Optional creation time (defaults to now)expiration_time- Optional expiration time for the primary keysubkeys_expiration- Optional expiration time for subkeyswhich_keys- Which subkeys to generate (seeSubkeyFlags)can_primary_sign- Whether the primary key can signcan_primary_expire- Whether the primary key can expire
§Returns
The generated key with public key (armored), secret key (binary), and fingerprint.
§Example
Generate a Curve25519 key (fast):
use wecanencrypt::{create_key, CipherSuite, SubkeyFlags};
let key = create_key(
"my_password",
&["Alice <alice@example.com>"],
CipherSuite::Cv25519,
None, None, None,
SubkeyFlags::all(),
false,
true,
).unwrap();
println!("Fingerprint: {}", key.fingerprint);
println!("Public key:\n{}", key.public_key);Generate an RSA-4096 key (slow, ~10s in release mode):
ⓘ
// Ignored: RSA-4096 key generation is slow (~10s release, ~600s debug)
use wecanencrypt::{create_key, CipherSuite, SubkeyFlags};
let key = create_key(
"my_password",
&["Bob <bob@example.com>"],
CipherSuite::Rsa4k,
None, None, None,
SubkeyFlags::all(),
false,
true,
).unwrap();