To perform the conversion, use your favorite XML library to extract the
BASE64 values in the Modulus and Exponent nodes, then create an EVP_PKEY
structure from these using the functions I'm pasting below. From here,
call PEM_write_PUBKEY to create a PEM file that will contain your RSA
public key and that can be used later by OpenSSL.
<CODE>
unsigned char *fromBase64(const char* szInput, int* pLen)
{
BIO *b64, *bmem;
size_t length = strlen(szInput);
// The length of BASE64 representation is always bigger
// than the actual data length, so the size given to
// the malloc below is sufficient to hold all the
// decoded data
unsigned char *buffer = (unsigned char *)malloc(length);
b64 = BIO_new(BIO_f_base64());
// No LF on the input string
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
bmem = BIO_new_mem_buf((void*)szInput, length);
bmem = BIO_push(b64, bmem);
*pLen = BIO_read(bmem, buffer, length);
BIO_free_all(bmem);
return buffer;
}
BIGNUM* BN_fromBase64(const char* szBase64)
{
BIGNUM* bn = NULL;
int iLen;
unsigned char* pbData = fromBase64(szBase64, &iLen);
if (iLen)
{
bn = BN_bin2bn(pbData, iLen, NULL);
}
free(pbData);
return bn;
}
EVP_PKEY* RSA_fromBase64(const char* szModulus, const char* szExp)
{
BIGNUM *n = BN_fromBase64(szModulus);
BIGNUM *e = BN_fromBase64(szExp);
if (!n) printf("Invalid encoding for modulus\n");
if (!e) printf("Invalid encoding for public exponent\n");
if (e && n)
{
EVP_PKEY* pRsaKey = EVP_PKEY_new();
RSA* rsa = RSA_new();
rsa->e = e;
rsa->n = n;
EVP_PKEY_assign_RSA(pRsaKey, rsa);
return pRsaKey;
}
else
{
if (n) BN_free(n);
if (e) BN_free(e);
return NULL;
}
}
</CODE>
Cheers,
--
Mounir IDRASSI
IDRIX
http://www.idrix.fr
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openss...@openssl.org
Automated List Manager majo...@openssl.org
The code is a generic OpenSSL C source that will compile using the
favorite compiler of your platform.
Did I understand your question correctly?
The code is a generic OpenSSL C source that will compile using the
favorite compiler of your platform.
Did I understand your question correctly?
--
Mounir IDRASSI
IDRIX
http://www.idrix.fr
> Hi
>
> Thanks for your response. In which lplatform do I compile/execute the below