Skip to content

Instantly share code, notes, and snippets.

@cmouse
Created July 12, 2016 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmouse/43ce3fa2c5d98032d608dc76911a7bda to your computer and use it in GitHub Desktop.
Save cmouse/43ce3fa2c5d98032d608dc76911a7bda to your computer and use it in GitHub Desktop.
Convert OpenSwan key to RSA key
#include <stdio.h>
#include <openssl/rsa.h>
#include <openssl/bn.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
int main(void) {
BIGNUM *bn;
RSA *rsa = RSA_new();
bn = BN_new();
BN_set_word(bn, <exponent, such as 0x010001 or 0x3>);
rsa->e = bn;
bn = NULL;
BN_hex2bn(&bn,"<modulus in hex without 0x>");
rsa->n = bn;
EVP_PKEY *pkey = EVP_PKEY_new();
EVP_PKEY_set1_RSA(pkey, rsa);
PEM_write_PUBKEY(stdout, pkey);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment