On Thursday, August 29, 2013 4:08:46 PM UTC-4, 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();
>
GetModulus() returns a Crypto++ Integer. Integer has a class method 
BitCount().

    unsigned int BitCount () const
        number of significant bits = floor(log2(abs(*this))) + 1

http://www.cryptopp.com/docs/ref/class_integer.html.

Jeff

   AutoSeededRandomPool pool;
    
    RSA::PrivateKey k1, k2, k3;
    k1.GenerateRandomWithKeySize(pool, 1023);
    k2.GenerateRandomWithKeySize(pool, 1024);
    k3.GenerateRandomWithKeySize(pool, 1025);
    
    cout << k1.GetModulus().BitCount() << endl;
    cout << k2.GetModulus().BitCount() << endl;
    cout << k3.GetModulus().BitCount() << endl;

    $ ./t.exe
    1023
    1024
    1025

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

Reply via email to