problem with decryption using private key

370 views
Skip to first unread message

liang wee

unread,
Jun 10, 2004, 6:54:13 AM6/10/04
to crypto...@eskimo.com
I am just wondering if the way I am doing decryption
is wrong. I am unable to get back the original text
even though I am using the correct pair of
public/private key. Below is the snippet of my code. I
am using crypto++5.1 with g++ 3.3 on fbsd 5.1


AutoSeededRandomPool rng;
char *message = "Hello World";
unsigned int length = pub.CiphertextLength (strlen
(message));
char *outstr = new char [length];

pub.Encrypt (rng, (byte *)message, strlen (message),
(byte *)outstr);

int length2 = priv.MaxPlaintextLength (length);
char *plaintext = new char [length2];
priv.Decrypt (rng, (byte *)outstr, length2, (byte *)plaintext);




__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/

Olga Sayenko

unread,
Jun 10, 2004, 10:38:29 AM6/10/04
to crypto...@eskimo.com
Crypto++ will not let you encrypt with the private key. It wants you to sign with the private
key. If you want your message protected you then have to encrypt with the public key (from a
different key pair).

=====
Olga Sayenko
http://www.cs.uic.edu/~osayenko
Department of Computer Science
University of Illinois at Chicago

Wei Dai

unread,
Jun 11, 2004, 7:29:17 PM6/11/04
to Olga Sayenko, crypto...@eskimo.com
On Thu, Jun 10, 2004 at 07:29:02AM -0700, Olga Sayenko wrote:
> Crypto++ will not let you encrypt with the private key. It wants you to sign with the private
> key. If you want your message protected you then have to encrypt with the public key (from a
> different key pair).

You're right that Crypto++ won't let you encrypt with the private key, but
that's not what liang is trying to do. The actual problem is something
else.

> > priv.Decrypt (rng, (byte *)outstr, length2, (byte *)plaintext);

The second parameter here needs to be ciphertextLength, i.e., "length"
rather than "length2".

liang wee

unread,
Jun 11, 2004, 11:46:18 PM6/11/04
to crypto...@eskimo.com
Hi,

After checking the code again, I notice that silly
mistake.

Just curius, is there any reason why crypto++ don't
support private key encryption ? If i am not wrong, a
message encrypted with a private key could only be
decrypted with the public key. Since only the owner
has the private key, this can be used to prove that
the message originated from the owner of this keypair.
It kind of serve the same purpose as signature.

Reply all
Reply to author
Forward
0 new messages