Hi Dave,

Thanks for your reply.

*1. If I can't use sprintf then how can I copy the enrypted message to a
character buffer. Bcoz so far I am sending the request to middleware in Char
Buffer using TCP /IP socket. How can I able to achieve now.*
**
*2. Actually I am using 2048 bit public key. So what is the right size I can
use. I tried to use RSA_size(rsa) , which gives core dump error. *

So any idea on the above points will help me a lot. Thanks.

On Tue, Apr 12, 2011 at 1:53 AM, Dave Thompson <dthomp...@prinpay.com>wrote:

> >       From: owner-openssl-us...@openssl.org On Behalf Of pattabi raman
> >       Sent: Sunday, 10 April, 2011 08:14
>
> >       I am using the below code snippet and am able to do the encytption.
>
> >       But I need to convert the encrypted format to Binary format inorder
> > to pass the encrypted key to a different system. Any one pls suggest
> > how to do the same ???
>
> What do you mean encrypted key? There is no encrypted key.
> There is an encrypt*ion* key -- your file publkey.pem --
> which you should already have obtained *from* the recipient.
>
> Do you mean the encrypted *data*, which is implied to be CardPin?
> The output (data) from RSA_public_encrypt is ALREADY binary.
> And it is NOT a null-terminated C string, so
>
> >       sprintf(encpin,
>
> >       "%s",encrypted);
>
> etc is wrong about 99.999999% of the time.
>
> Note that most actual systems do not use just encryption;
> they usually need to combine with additional information.
> Perhaps what you need is some ASN.1 structure *containing*
> your data, or an XML structure, etc etc.
>
> Also, your code is hard to read. Frequently people post code
> with too little white space, but yours has far too much.
> In several places you check for an error and print a message,
> but then proceed to use the null pointer anyway; if/when the
> error arises, this will be very wrong. In most cases there is
> additional information that would be helpful in your error
> message(s): errno/strerror for fopen (or other I/O) problems,
> or the OpenSSL error stack (e.g. ERR_print_errors_fp) for openssl.
>
> Finally, you are assuming 256 bytes is enough for the RSA
> encrypted value. If you ever get a publickey over 2048 bits
> this will fail badly. It's safer to make this variable
> if your environment or protocol allows that, or at least
> check that the size of the key provided is not too big.
>
>
>
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> User Support Mailing List                    openssl-users@openssl.org
> Automated List Manager                           majord...@openssl.org
>

Reply via email to