(Answer) (Category) Crypto++ Faq-O-Matic :
How do I encrypt a message using a *private* key? (example of using signature with recovery)
Moderator: weidai (inherited from parent)
The Crypto++ API does not allow you to encrypt using a private key, because that is not a valid cryptographic concept. Perhaps what you really want to do is to use the private key to sign a message in such a way that you can recover the message from the signature during the signature verification process, thus avoiding having to send the message separately.

Here is some sample code for doing this:

        #include "rsa.h"
        #include "pssr.h"
        #include "files.h"
// ...
FileSource f("rsa1024.dat", true, new HexDecoder); RSASS<PSSR, SHA>::Signer signer(f); RSASS<PSSR, SHA>::Verifier verifier(signer);
// sign byte message[] = "test"; unsigned int messageLen = sizeof(message); SecByteBlock signature(signer.MaxSignatureLength(messageLen)); AutoSeededRandomPool rng; unsigned int signatureLen = signer.SignMessageWithRecovery(rng, message, messageLen, NULL, 0, signature);
// verify and recover SecByteBlock recovered(verifier.MaxRecoverableLengthFromSignatureLength(signatureLen)); DecodingResult result = verifier.RecoverMessage(recovered, NULL, 0, signature, signatureLen); if (!result.isValidCoding) throw InvalidSignature(); unsigned int recoveredLen = result.messageLength;

2008-Aug-24 4:56am weidai, aspecialj
[Append to This Answer]
2008-Aug-24 4:56am
Previous: (Answer) How do I use a public key cryptosystem or signature scheme?
Next: (Answer) How can I use an RSA key from Crypto++ in openssl?
This document is: http://www.cryptopp.com/cgi-bin/fom.cgi?file=96
[Search] [Appearance] [Show Expert Edit Commands]
This is a Faq-O-Matic 2.721.
This FAQ is administered by Wei Dai.