[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ssh_pki_export_privkey_file for SSH_KEYTYPE_RSA key returns SSH_ERROR


I'm new to programming using libssh. 

When i take the keygen.c example file in the examples directory, it fails during execution when i change the keytype.

[tdkuehnel@ multiboot examples]$ ./keygen 
Failed to write private key file[tdkuehnel@ multiboot examples]$ 

/*    rv = ssh_pki_generate(SSH_KEYTYPE_ED25519, 0, &key);*/
    rv = ssh_pki_generate(SSH_KEYTYPE_RSA, 1024, &key);

Do i miss additional steps in preparing the rsa key to be exported ?

Complete code:

#include <libssh/libssh.h>
#include <stdio.h>

int main(void)
{
    ssh_key key = NULL;
    int rv;

    /* Generate a new ED25519 private key file */
/*    rv = ssh_pki_generate(SSH_KEYTYPE_ED25519, 0, &key);*/
    rv = ssh_pki_generate(SSH_KEYTYPE_RSA, 1024, &key);
    if (rv != SSH_OK) {
        fprintf(stderr, "Failed to generate private key");
	return -1;
    }

    /* Write it to a file testkey in the current dirrectory */
    rv = ssh_pki_export_privkey_file(key, NULL, NULL, NULL, "testkey");
    if (rv != SSH_OK) {
        fprintf(stderr, "Failed to write private key file");
	return -1;
    }

    return 0;
}



-- 
Torsten Kuehnel <tdkuehnel@xxxxxxxxxxxxxxxxxxxxx>

Archive administrator: postmaster@lists.cynapses.org