diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/CMakeLists.txt | 4 | ||||
-rw-r--r-- | examples/keygen.c | 41 |
2 files changed, 45 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 01dbf2d4..85bd3879 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -70,6 +70,10 @@ add_executable(senddata senddata.c ${examples_SRCS}) target_compile_options(senddata PRIVATE ${DEFAULT_C_COMPILE_FLAGS}) target_link_libraries(senddata ${LIBSSH_SHARED_LIBRARY}) +add_executable(keygen keygen.c) +target_compile_options(keygen PRIVATE ${DEFAULT_C_COMPILE_FLAGS}) +target_link_libraries(keygen ${LIBSSH_SHARED_LIBRARY}) + add_executable(libsshpp libsshpp.cpp) target_link_libraries(libsshpp ${LIBSSH_SHARED_LIBRARY}) diff --git a/examples/keygen.c b/examples/keygen.c new file mode 100644 index 00000000..2ab00113 --- /dev/null +++ b/examples/keygen.c @@ -0,0 +1,41 @@ +/* keygen.c + * Sample implementation of ssh-keygen using libssh + */ + +/* +Copyright 2019 Red Hat, Inc. + +Author: Jakub Jelen <jjelen@redhat.com> + +This file is part of the SSH Library + +You are free to copy this file, modify it in any way, consider it being public +domain. This does not apply to the rest of the library though, but it is +allowed to cut-and-paste working code from this file to any license of +program. + */ + +#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); + 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; +} |