LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

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


Hi,

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
char));
iend = keybuf;
size = i2d_RSAPublicKey(rsa, &iend);
/* size returns the size of public key in bytes */
printf("\n");
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 junk..is it right?

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

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

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

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
Quote:
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.

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

Quote:
if i use %c instead %X it is printing some junk..is 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.
 
  


Reply


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


All times are GMT -5. The time now is 09:27 PM.

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