Created
July 12, 2016 13:06
-
-
Save cmouse/43ce3fa2c5d98032d608dc76911a7bda to your computer and use it in GitHub Desktop.
Convert OpenSwan key to RSA key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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