I am trying to verify an XML Digital Signature and was wondering
if there is a more direct way of doing this. I have the digest
calculation working fine, but now I am trying to do the RSA
key stuff and feel like "there must be a better way". Here's how
I currently do it:

1] Read in the XML file, saving the Modulus and Exponent strings
found in the RSAKey element.

2] Turn each of these into an Integer like thus:

                StringSource mod_s( xmlString, true, new Base64Decoder);
                unsigned long mrs = mod_s.MaxRetrievable();
                char* sstr = new char[mrs];
                mod_s.Get( (unsigned char*)mod_sstr, mrs );
                Integer mod(mod_sstr);

3] Create the key:

                RSA::PrivateKey key;
                key.SetModulus( mod );
                key.SetPublicExponent( exp );

4] Create the signer and verifier:

                RSASSA_PKCS1v15_SHA_Signer rsaSign(key);
                RSASSA_PKCS1v15_SHA_Verifier rsaVer(rsaSign);

5] Get the SignatureValue from the XML file:

                StringSource sig_s( sigv->Value(), true, new Base64Decoder );
                unsigned long mr = sig_s.MaxRetrievable();
                unsigned char* v = new unsigned char[mr];
                sig_s.Get( v, mr );

6] Now verify:
                if ( !rsaVer.VerifyMessage( (const unsigned char*)signedInfo.c_str(), 
signedInfo.size(),
                                            v, mr ) )
                {
                    std::cout << "Invalid license : SignatureValue mismatch\n";
                    return 1;
                }

Now it seems to me that there should be a faster way of creating the key, without
having to create some temp buffers esp. But if I pass in the StringSource directly
to the Integer, I get complaints in the verifier of all places, about
 "CryptoMaterial: this object contains invalid values"

Perhaps I need to read up on Filters or something? Any help would be
appreciated.

--
Jonathan Arnold     (mailto:[EMAIL PROTECTED])
Amazing Developments       http://www.buddydog.org

Genius may have its limitations, but stupidity is not
thus handicapped. -- Elbert Hubbard



Reply via email to