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...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 );