Ok, I think I've found the official method.... privateKey.MaxImage().ByteCount();
On Thursday, August 29, 2013 1:08:46 PM UTC-7, Stu wrote: > > The RSA keysize is the length of the modulus. If I generate a new key > using the GenerateRandomWithKeySize function, then I know what the keySize > is because I just set it. However, if I load the RSA key from a file or > some other location, I need a way to determine what the keysize is. > > The most direct way would be as follows: > > privateKey.GetModulus().ByteCount(); > > However, this would actually return the number of bytes needed to hold the > specific modulus, which could possibly be less than the number of bytes for > the maximum modulus. ie, if I used 256-byte RSA, the random modulus might > have all 0's in the last byte and therefore only take up 255 bytes...of > course I could round up to the nearest power of 2 but that is messy. > > Another way that I know works is this: > > CryptoPP::RSA::PrivateKey privateKey; > RSAES_OAEP_SHA_Decryptor decryptor( privateKey ); > int keySizeBytes = decryptor.FixedCiphertextLength(); > > However this is very obtuse and requires creating a high level decryptor > object only to be destroyed. I'd like to find a better way. > > From the documentation of PrivateKey here: > http://www.cryptopp.com/docs/ref/class_private_key.html > > virtual void > GenerateRandom<http://www.cryptopp.com/docs/ref/class_generatable_crypto_material.html#abe368b52db1ca7079b690f2d6e605f7a>( > RandomNumberGenerator<http://www.cryptopp.com/docs/ref/class_random_number_generator.html>&rng, > const > NameValuePairs<http://www.cryptopp.com/docs/ref/class_name_value_pairs.html>¶ms= > g_nullNameValuePairs<http://www.cryptopp.com/docs/ref/cryptlib_8h.html#aa9048ef24353685fd0dcc4180c6884c2> > ) generate a random key or crypto parameters > void > GenerateRandomWithKeySize<http://www.cryptopp.com/docs/ref/class_generatable_crypto_material.html#a38d492343c32e530a5c2781b5797f755>( > RandomNumberGenerator<http://www.cryptopp.com/docs/ref/class_random_number_generator.html>&rng, > unsigned int keySize) > calls the above function with a > NameValuePairs<http://www.cryptopp.com/docs/ref/class_name_value_pairs.html>object > that just specifies "KeySize" > ...which would seem to imply that I can look up "KeySize" in the list of > NameValuePairs. However, when I call > > privateKey.GetValueNames() > > it does not list "KeySize" or anything similar. I tried the following all > of which did not work: > > privateKey.GetIntValue( "KeySize", value ); > privateKey.GetIntValue( "ModulusSize", value ); > > > -- -- 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. --- You received this message because you are subscribed to the Google Groups "Crypto++ Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
