Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-09-2010, 07:47 AM   #1
LQ Newbie
Registered: Aug 2010
Posts: 1

Rep: Reputation: 0
sending RSA public/private keys into calling function


I am newbie to openssl...

My calling application will accept only strings and interger.

we are replacing RSA bsafe library to openssl. using RSA bsafe, we have generated the private and public key in BER format. Then convert the keys, BER format into ASCII format to send the calling function. (these everything done by using RSA supplied bsafe library)

same way i have to right using openssl..i m now able convert the RSA public and private key into DER format

rsa = RSA_generate_key(1024, 3, NULL, NULL);
size_t size;
unsigned char *iend, *keybuf;
int i;
size = i2d_RSAPublicKey(rsa, NULL);
printf("size %d\n",size);
keybuf = (unsigned char *) malloc(size * sizeof( unsigned
iend = keybuf;
size = i2d_RSAPublicKey(rsa, &iend);
/* size returns the size of public key in bytes */
printf("key :");
for(i=0;i<size;++i) {
printf("\n%02X", keybuf[i]);

1. is it possible to convert this DER format into ASCII?

2. I am able to print the keybuf value into stdout in the as mentioned below

size 138
key : 30818702818100BAEF6AB1AD2503FFDC900B612BA2BCED9AF74E337A43B21D1FF69A30651AD7A492C1E199CB40A9DF693

is it possible to convert the key into DER format again?

if i use %c instead %X it is printing some it right?

for(i=0;i<size;++i) {
printf("\n%c", keybuf[i]);

ou^Y9eP>@3nJp%}K8sY* O\

Thanks in advance,
Old 10-10-2010, 05:55 AM   #2
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Stretch (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Originally Posted by krishna_san View Post
1. is it possible to convert this DER format into ASCII?
You don't say what you mean by an ASCII format. If you just mean a hex string (as you gave in your example), then you can use sprintf to convert it in a buffer (or code the conversion yourself). If you mean base64 strings, then there are libraries you can use.

2. Is it possible to convert the key into DER format again?
Same as above, use sscanf or a conversion library.

if i use %c instead %X it is printing some it right?
It is as expected, because you are printing out binary data as if it is characters; some of these characters are not printable, and some are not even ASCII (top bit set). This is not a usable way to represent the data.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Public and Private Keys??? ajeetraina Linux - Server 2 05-10-2008 02:15 PM
SSH Private RSA keys keysorsoze Linux - Security 4 11-22-2006 10:44 PM
question about private and public keys mac1234mac Linux - Security 25 04-13-2006 02:04 PM
Using GPG without public or private keys darin3200 Linux - Security 3 01-10-2005 03:40 AM
Help with SSH and public/private keys stodge Linux - Security 5 05-14-2003 01:22 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:29 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration