Blame examples/keygen.c

Packit 6c0a39
/* keygen.c
Packit 6c0a39
 * Sample implementation of ssh-keygen using libssh
Packit 6c0a39
 */
Packit 6c0a39
Packit 6c0a39
/*
Packit 6c0a39
Copyright 2019 Red Hat, Inc.
Packit 6c0a39
Packit 6c0a39
Author: Jakub Jelen <jjelen@redhat.com>
Packit 6c0a39
Packit 6c0a39
This file is part of the SSH Library
Packit 6c0a39
Packit 6c0a39
You are free to copy this file, modify it in any way, consider it being public
Packit 6c0a39
domain. This does not apply to the rest of the library though, but it is
Packit 6c0a39
allowed to cut-and-paste working code from this file to any license of
Packit 6c0a39
program.
Packit 6c0a39
 */
Packit 6c0a39
Packit 6c0a39
#include <libssh/libssh.h>
Packit 6c0a39
#include <stdio.h>
Packit 6c0a39
Packit 6c0a39
int main(void)
Packit 6c0a39
{
Packit 6c0a39
    ssh_key key = NULL;
Packit 6c0a39
    int rv;
Packit 6c0a39
Packit 6c0a39
    /* Generate a new ED25519 private key file */
Packit 6c0a39
    rv = ssh_pki_generate(SSH_KEYTYPE_ED25519, 0, &key);
Packit 6c0a39
    if (rv != SSH_OK) {
Packit 6c0a39
        fprintf(stderr, "Failed to generate private key");
Packit 6c0a39
	return -1;
Packit 6c0a39
    }
Packit 6c0a39
Packit 6c0a39
    /* Write it to a file testkey in the current dirrectory */
Packit 6c0a39
    rv = ssh_pki_export_privkey_file(key, NULL, NULL, NULL, "testkey");
Packit 6c0a39
    if (rv != SSH_OK) {
Packit 6c0a39
        fprintf(stderr, "Failed to write private key file");
Packit 6c0a39
	return -1;
Packit 6c0a39
    }
Packit 6c0a39
Packit 6c0a39
    return 0;
Packit 6c0a39
}