Skip to content

Instantly share code, notes, and snippets.

@Ge0
Created April 28, 2019 13:11
Show Gist options
  • Save Ge0/e99ac19dece5ceef6af02366f185d683 to your computer and use it in GitHub Desktop.
Save Ge0/e99ac19dece5ceef6af02366f185d683 to your computer and use it in GitHub Desktop.
/* gcc -o test-pem test-pem.c -lssl -lcrypto */
#include <stdio.h>
#include <stdlib.h>
#include <openssl/pem.h>
int main(int argc, char* argv[]) {
FILE *fp = NULL;
EVP_PKEY* key = NULL;
if (argc < 2) {
fprintf(stderr, "Usage: %s PEM_FILE\n", argv[0]);
exit(EXIT_FAILURE);
}
if (NULL == (fp = fopen(argv[1], "rb"))) {
fprintf(stderr, "Could not open %s.\n", argv[1]);
exit(EXIT_FAILURE);
}
key = PEM_read_PUBKEY(fp, NULL, NULL, NULL);
printf("key = %p\n", key);
fclose(fp);
EVP_PKEY_free(key);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment