I have a following function for signing strings:

void CCryptografia::RSASign(RSASS<PSSR, SHA>::Signer& signer, string&
stream)
{
        try
        {
                string signed_str;  // Signed string is stored here
                unsigned int messageLen = stream.length();
                AutoSeededRandomPool rng;

                SecByteBlock signature(signer.MaxSignatureLength(messageLen));
                unsigned int signatureLen =
                        signer.SignMessageWithRecovery( rng,
                                                                           
(byte*)stream.c_str(),
                                                                           
messageLen,
                                                                           NULL,
                                                                           0,
                                                                           
signature);
                // Store data to string
                signed_str.assign((char*)signature.data());

                if(signed_str.length() > signatureLen)
                {       // In some cases the data contains extra characters.
                        signed_str.erase(signatureLen);
                }
                else if(signed_str.length() < signatureLen)
                {       // This is the error that occurs
                        throw RSASignEx(ERR, "Signed string too short.");
                }

                // Replace original string with signed and encoded one
                Base64Encode(signed_str, stream);
        }
        catch (...)
        {
                // Exception handling...
        }
}

And if I call the previous function like this:

string text = "Clear text to sign...";
string private_key =
"MIICdAIBADANBgkqhkiG9w0BAQEFAASCAl4wggJaAgEAAoGBALyem3b2erPfT8opXTkkQhg1
tlHIfNXgVK6OSGEZihhna/E/uUmFF65kXRCKGueDL/abQhBSfwMrdbrH/yOPl
+6wSdr89LMi bPxtnhT6OSagcqPLQbC3dKc/
c2kLMamtfy17yuFl9iCXKEpf0PiVz1RJgs1INsdnDyNpL2Zw OlVdAgERAoGAWMMb
+79IzR3LMfVZC9TTzyhVzCIcoOIJu45ALbGqZdZQ6f/euS+SrGt3FteU
MLY0sEkQB65Z41++7nw71H/
PBhm448VYL2X8w3jVzDGNZoNP8A2mI7gCB5o8E9VOF7Qml4YR kqulDc3rWfzA1KitcY
+sKhEsZ6p+JHE9Wp9U39ECQQDHFHiIZzVZKsVnjgIgAafOeri0rUnL
VLPqEemFpvKyPCQEop5RFrU9abIEDAsUG2N0lqoxoeba+e4jTgfpfw7rAkEA8ox
+cTIZEIkX pUnA8OsE+u4M
+ZNbBRujLaHVYETEnHEHekLraCCuBCp5Iqspm0Nfg55JshaEQckn1T799Cbq
1wJAUflezsEV94oVDIXEo8RyRfZMDik8gOakb3DJkWLcZ4Is8tmMe74OZJTu8puMF1aSXS76
ySSMPAyPO7a39rvY9wJBAJzxfv3zPWUNaacvuRRb1gvHNZJuaBJdLVnDEZik97CFXzD
+H9n3 By/fP1Kq/M3gTNyxtzb/
gsEnznrshjSRpwMCQBHSovRne9TxkJBfUclkiPy8nNZpXsfBGda7 LHNU5ZxbS/
yoMDqrx0ck7ITEwLz8kqtFSRt7awrN3g19JG3KyY4= ";

int success = 0, failed = 0;

CryptoPP::StringSource ss_priv(private_key, true, new
CryptoPP::Base64Decoder);
CryptoPP::RSASS<CryptoPP::PSSR, CryptoPP::SHA>::Signer
signer(ss_priv);

for(int i = 0; i < 100; i++)  // Do a testing loop
{
        try
        {
                // Sign the string
                Sec.RSASign(rng, signer, text);
                success++;  // Signing OK
        }
        catch (...)
        {       // Signing has failed.
                failed++;
        }

        text.assign("Clear text to sign...");
}

Allmost half of the function calls fails. All failures occur because
the signed string is shorter
then it should be. Line "signed_str.assign((char*)signature.data());"
assigns the signed string from (SecByteBlock) signature to a
stl::string and when I attached a debugger to application it really
shows that the signature contains less data than it should be.
Function SignMessageWithRecovery returns allways the correct size
(128). (SecByteBlock) signature's m_size member is also allways 128
but the data is shorter.

I'm using VS2005 and Cryptopp 5.2.2. Does any one have any idea why
signing fails?
--~--~---------~--~----~------------~-------~--~----~
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