Skip to content

Instantly share code, notes, and snippets.

@rzhw
Last active August 29, 2015 14:21
Show Gist options
  • Save rzhw/8b006cd1ae689ece417b to your computer and use it in GitHub Desktop.
Save rzhw/8b006cd1ae689ece417b to your computer and use it in GitHub Desktop.
PEM RSA public key to RSA struct
// gcc pempublickeytest.c -lssl -lcrypto -I/usr/include/openssl/ -o pempublickeytest
#include <stdio.h>
#include <stdlib.h>
#include <openssl/rsa.h>
#include <openssl/bio.h>
#include <openssl/pem.h>
int main() {
BIO *bio = BIO_new_file("blah_rsa.pub.pem", "r");
RSA *rsa = PEM_read_bio_RSAPublicKey(bio, NULL, NULL, NULL);
printf("rsa: %p, rsa->n: %p, &rsa->n: %p\n", rsa, rsa->n, &rsa->n);
printf("BN_num_bits: %d\n", BN_num_bits(rsa->n));
printf("rsa->version: %ld, &rsa->version: %p\n", rsa->version, &rsa->version);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment