Skip to content

Saving public/private portions of key to filesystem for long-term storage #542

Answered by LoganSchmalz
LoganSchmalz asked this question in Q&A
Discussion options

You must be logged in to vote

Solved, example code that tries to load a public/private keypair from a file before generating a new one:

fn create_signing_handle(context: &mut Context, primary_key_handle: KeyHandle) -> KeyHandle {
    let pub_file = File::open("key.pub");
    let priv_file = File::open("key.priv");
    if let (Ok(mut pub_file), Ok(mut priv_file)) = (pub_file, priv_file) {
        let mut buf = vec![];
        let _ = pub_file.read_to_end(&mut buf);
        let pub_key = Public::unmarshall(&buf).unwrap();
        buf.clear();
        let _ = priv_file.read_to_end(&mut buf);
        let priv_key = Private::try_from(buf.clone()).unwrap();

        let handle = context
            .execute_with_nullauth_se…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by LoganSchmalz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant