RSA encrypt with private and decrypt with public key

1,636 views
Skip to first unread message
Message has been deleted
Message has been deleted

Azzuro

unread,
Aug 25, 2008, 6:15:12 AM8/25/08
to cryptop...@googlegroups.com

Hy
I hope somebody can help me.
I'm new with crypto++.
I try to encrypt an Message with the private Key of RSA.

My example Code:

to generate Key files:
{
string PrivateKeyFile = "key.pv";
string PublicKeyFile = "key.pb";
AutoSeededRandomPool rng;
int e = 65537;
RSAES_OAEP_SHA_Decryptor Decryptor( rng, 1024 , e );
HexEncoder privFile(new FileSink( PrivateKeyFile.c_str() ));

Decryptor.DEREncode(privFile);
privFile.MessageEnd();
RSAES_OAEP_SHA_Encryptor Encryptor(Decryptor);
HexEncoder pubFile(new FileSink( PublicKeyFile.c_str() ) );
Encryptor.DEREncode(pubFile);
pubFile.MessageEnd();
}

after that ich try to encrypt a message :
{
const char * pubFilename = "key.pv";


FileSource pubFile(pubFilename, true, new HexDecoder);

RSAES_OAEP_SHA_Encryptor pub(pubFile);
AutoSeededRandomPool randPool;
string * result = new string();

StringSource(
message,
true,
new PK_EncryptorFilter(randPool, pub, new
HexEncoder(new
StringSink(*result))));

cout << *result << endl;

}
to decrypt the cipher
{
const char * privFilename = "key.pb";
AutoSeededRandomPool randPool;

FileSource privFile(privFilename, true, new HexDecoder);
RSAES_OAEP_SHA_Decryptor priv(privFile);

string *result2 = new string();
StringSource(
cipher,
true,
new HexDecoder(new PK_DecryptorFilter(randPool, priv,
new
StringSink(*result2))));
cout << *result2 << endl;

}
the error:
terminate called after throwing an instance of 'CryptoPP::BERDecodeErr'
what(): BER decode error


I need this for my bachelor thesis!
Thank a lot

ps.: I post also here :
http://groups.google.com/group/cryptopp-users/browse_thread/thread/3c051aae6f11fbaf
--
View this message in context: http://www.nabble.com/RSA-encrypt-with-private-and-decrypt-with-public-key-tp19141140p19141140.html
Sent from the Crypto++ Users mailing list archive at Nabble.com.

Erwan Herfroy

unread,
Aug 25, 2008, 12:14:00 PM8/25/08
to Crypto++ Users
Crypto++ will not let you encrypt with the private key. You can sign
with the private
key, though. Refer to
http://groups.google.com/group/cryptopp-users/browse_thread/thread/8b65da31025f20e7/a985e32243b24b93?lnk=gst&q=private+key+sign#a985e32243b24b93.
You can also refer to the very good tutorial at
http://www.codeproject.com/KB/cpp/RsaSignatureAppendix.aspx.
> ps.: I post also here :http://groups.google.com/group/cryptopp-users/browse_thread/thread/3c...
> --
> View this message in context:http://www.nabble.com/RSA-encrypt-with-private-and-decrypt-with-publi...
Reply all
Reply to author
Forward
0 new messages