There is indeed an error. Try using the Integer constructor that takes a byte * and a length (i.e., a byte array) as inputs, instead of char * (i.e., zero-terminated C string).
----- Original Message -----
Sent: Wednesday, September 13, 2006 3:37 PM
Subject: Re: message too long for this public key. Was: system.security.cryptography.rsa.toxmlstring

Hi Mathieu
 
your function Base64ToInteger is correct, I tested it.
 
if u tried that line
StringSource(mod_sstr, true, new Base64Encoder(new StringSink(result)));
 
u will found out that is working correctly.
 
but IntegerToBase64  function returns the wrong result, however I don't see any errors in code.
 
May be there is another way for using DEREncode function to return the correct results.

Regards
Haytham Mohammed
Mathieu Malaterre <[EMAIL PROTECTED]> wrote:
I went one step further and created back the base64 string:

void IntegerToBase64(Integer const &xmlint, char *base64String)
{
std::string result;
Base64Encoder enc64(new StringSink(result));
xmlint.DEREncode(enc64);
enc64.MessageEnd();
strcpy(base64String, result.c_str());
}

And I get:

AgQFi3DG

which is pretty alarming, but would make sense since 93024454 is not
that big of a number. So my guess is that my function Base64ToInteger is
incorrect.

Mathieu

Jeffrey Walton wrote:
> Hi Mathieu,
>
> Here's what I got after adding a sanity check:
> Modulus: 93024454
> Exponent: 0
>
> Jeff
>
> CryptoPP::RSA::PublicKey CreatePublicKey()
> {
> ...
> CryptoPP::Integer mod, exp;
> Base64ToInteger(modulus, mod);
> Base64ToInteger(exponent, exp);
>
> std::cout << "Modulus: " << mod << std::endl;
> std::cout << "Exponent: " << exp << std::endl;
>
> CryptoPP::RSA::PublicKey key;
> }
>
> On 9/11/06, Mathieu Malaterre <[EMAIL PROTECTED]>wrote:
>> Thanks Jeffrey,
>>
>> Actually what I am trying to do is quite simple. It's just that I
>> cannot find the information on internet(*). Here is what I have so far:
>>
>> void Base64ToInteger(const char *base64String, Integer &xmlint)
>> {
>> StringSource mod_s( base64String, true, new Base64Decoder);
>> unsigned long mrs = mod_s.MaxRetrievable();
>> char* mod_sstr = new char[mrs];
>> mod_s.Get( (unsigned char*)mod_sstr, mrs );
>> xmlint = Integer(mod_sstr);
>> delete[] mod_sstr;
>> }
>>
>> RSA::PublicKey CreatePublicKey()
>> {
>> const char modulus[] =
>> "wehzXu32ipNZZkhWqYMVrKoWs4o5AfPKZbdTLVVt8jPfC09yKzC/ajJTeGm87moeU+yZ6Lz8PXsKOmxxNFBE3vQpbMEq++fCjhI0QdC4q/h0H6FePN7MC3WZmR0hpI3yp5sGNfBSBMPNRsnpEGI00ByxQp1N8R9hj9pc0OvwswE=";
>>
>> const char exponent[] = "AQAB";
>> Integer mod, exp;
>> Base64ToInteger(modulus, mod);
>> Base64ToInteger(exponent, exp);
>>
>> RSA::PublicKey key;
>> key.Initialize(mod, exp);
>> return key;
>> }
>>
>> int main()
>> {
>> RSA::PublicKey pubKey = CreatePublicKey();
>> const char message[] = "hello";
>> RSAES_OAEP_SHA_Encryptor pub(pubKey);
>> AutoSeededRandomPool randPool;
>> std::string result;
>> StringSource(message, true, new PK_EncryptorFilter(randPool, pub,
>> new Base64Encoder(new StringSink(result))));
>> }
>>
>> All I get is:
>>
>> terminate called after throwing an instance of
>> 'CryptoPP::InvalidArgument'
>> what(): RSA/OAEP-MGF1(SHA-1): message too long for this public key
>>
>>
>> All I am trying is do the RSA encryption by setting parameter
>> one by
>> one, reading each XML elements(**).
>>
>> Any suggestion ? Thanks
>> Mathieu
>>
>> (*)
>> So I found this post by accident.
>> http://www.mail-archive.com/[email protected]/msg01619.html
>> Indeed if you try to find this post by using keyword like 'SetModulus'
>> or 'SetPublicExponent', I cannot find it either by using the internal
>> search engine or via google:
>> http://www.google.com/search?hl=en&q=SetPublicExponent+site%3Awww.mail-archive.com
>>
>>
>> (**)
>> http://www.w3.org/TR/xmldsig-core/#sec-RSAKeyValue
>>
>> Jeffrey Walton wrote:
>> > Hi Mathieu,
>> >
>> > I would assume you would provide a Cryptographic Sservice Package
>> > (CSP). But I've never looked into in.
>> >
>> >> I am looking to replace the .NET Framework
>> >> crypto class by the CryptoPP one.
>> > You probably cannot replace the .NET cryptography package per se. You
>> > would provide the CSP, and then set it as the machine default CSP.
>> > Again, I'm shooting from the hip.
>> >
>> > Jeff
>> >
>> > On 9/11/06, Mathieu Malaterre <[EMAIL PROTECTED]>wrote:
>> >> Hello,
>> >>
>> >> I am looking to replace the .NET Framework crypto class by the
>> >> CryptoPP
>> >> one. Has anyone try doing so ? Could they share there experience ?
>> I am
>> >> having a hard time understanding how to setup manually all the
>> >> parameters (Modulus, Exponent, InverseQ...) are there any examples
>> >> somewhere that I can look at ?
>> >> Finally the only post I was able to find mentionned a
>> problem of
>> >> endianness:
>> >>
>> >>
>> http://www.eggheadcafe.com/forumarchives/win32programmerdirectxvideo/dec2005/post24849638.asp
>>
>> >>
>> >>
>> >> Is this something that has been solved since ?
>> >>
>> >> Thanks for your time,
>> >> Mathieu
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Get your email and more, right on the new Yahoo.com

Reply via email to