Hi Thanks for your response. In which platform do I compile/execute the below CODE? I only have UNIX command line and Windows available.
Regards Vivek Panikulam ________________________________ From: Mounir IDRASSI <mounir.idra...@idrix.net> To: openssl-users@openssl.org Sent: Fri, September 17, 2010 10:07:10 PM Subject: Re: How to convert RSA public key XML format to PEM or ASCII format Hi, 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 > Hi All > > I have a RSA public key provided in the below format and would like to > know how > to convert it into a format like PEM or any other format which can be read > by > openssl. I didnt find any conclusive solutions for this on www. Will > the application which generated this key format be capable of generating > the > same key in PEM or ASCII format? > > <?xml version="1.0" encoding="UTF-8" ?> > - <RSAKeyValue> > ><Modulus>dhjffljkglejDHKJFHkjhhhhhSLWSKWLlkNKMNCKJBCKJFKJFBNCJKNLKNCLKMNDLKJSLKWJLJSjsSJJSDDDDDDDDDddddkjswlqqq</Modulus> >> > > <Exponent>AQAB</Exponent> > </RSAKeyValue> > > Regards > Vivek Panikulam > > > > ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org