Skip to main content

Generate an Ed25519 Key Pair

Run the Example

You can generate an example ED25519 Key Pair inside an ephemeral vault by running the following command from the client crate.

cargo run --example cli generate-key --key-type Ed25519 --vault-path "vault_path" --record-path "record_path"

Expected Output

[2022-06-28T12:52:22Z INFO  cli] Generating keys with type Ed25519
[2022-06-28T12:52:22Z INFO cli] Using output location: vault_path=vault_path, record_path=record_path
[2022-06-28T12:52:22Z INFO cli] Key generation successful? true
[2022-06-28T12:52:22Z INFO cli] Creating public key
[2022-06-28T12:52:22Z INFO cli] Public key is "JziUUMhit2Nvds3TXbtzOlJpDEfpbYiTC9qI+8Pp1x0=" (Base64)

Example Code

async fn command_generate_key(key_type: String, location: VaultLocation) {
info!("Generating keys with type {}", key_type);

let client = Client::default();
let (vault_path, record_path) = (location.vault_path, location.record_path);

"Using output location: vault_path={}, record_path={}",
vault_path, record_path

let keytype = match key_type.to_lowercase().as_str() {
"ed25519" => KeyType::Ed25519,
"x25519" => KeyType::X25519,
_ => {
error!("Unknown key type: {}", key_type);

let output_location =
stronghold::Location::generic(vault_path.as_bytes().to_vec(), record_path.as_bytes().to_vec());

let generate_key_procedure = GenerateKey {
ty: keytype.clone(),
output: output_location.clone(),

let procedure_result = client.execute_procedure(StrongholdProcedure::GenerateKey(generate_key_procedure));

info!("Key generation successful? {}", procedure_result.is_ok());

// get the public key
let public_key_procedure = stronghold::procedures::PublicKey {
ty: keytype,
private_key: output_location,

info!("Creating public key");
let procedure_result = client.execute_procedure(StrongholdProcedure::PublicKey(public_key_procedure));


let procedure_result = procedure_result.unwrap();
let output: Vec<u8> = procedure_result.into();
info!(r#"Public key is "{}" (Base64)"#, base64::encode(output));