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.

On Aug 25, 5:15 am, Azzuro <[EMAIL PROTECTED]> wrote:
> 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/3c...
> --
> View this message in 
> context:http://www.nabble.com/RSA-encrypt-with-private-and-decrypt-with-publi...
> Sent from the Crypto++ Users mailing list archive at Nabble.com.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [EMAIL PROTECTED]
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

Reply via email to