Jean-Pierre,

    Taken from test.cpp, this is the way I am generating RSA keys and it
seems to work great. The one thing I am not sure about with this method is
if the keys generated are tied to the algorithm set I am specifying
(RSAES_OAEP_SHA) or if they are "generic" RSA keys. Here you go:

  AutoSeededRandomPool randPool;
// generate the private key, which is DER encoded, then base64 encoded into
sTempPrivateKey
  Base64Encoder privKey(new StringSink(sTempPrivateKey), false);
  RSAES_OAEP_SHA_Decryptor privKeyGen(randPool, dwSpecKeyLength);
  privKeyGen.DEREncode(privKey);
  privKey.MessageEnd();

// generate the public key, which is DER encoded, then base64 encoded into
sTempPublicKey
  Base64Encoder pubKey(new StringSink(sTempPublicKey), false);
  RSAES_OAEP_SHA_Encryptor pubKeyGen(privKeyGen);
  pubKeyGen.DEREncode(pubKey);
  pubKey.MessageEnd();

I then use these keys by base64 decoding them and passing the DER encoded
material to the constructor of either the ecnryptor (for public key) or
decryptor (for private key). Good luck!

Jason von Nieda

----- Original Message -----
From: "Jean-Pierre Parent" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, October 26, 2002 8:23 PM
Subject: Problem generating RSA key pairs


> Hi folks,
>
> I've been trying to generate RSA key pairs. To do this I looked at the
example
> provided in Denis Bider's Crypto++ User Guide. The following:
>
> #include "rsa.h"
> #include "osrng.h"
>
> using namespace CryptoPP;
> using namespace std;
>
> int main() {
> // InvertibleRSAFunction is used directly only because the private key
> // won't actually be used to perform any cryptographic operation;
> // otherwise, an appropriate typedef'ed type from rsa.h would have been
used.
> AutoSeededRandomPool rng;
> InvertibleRSAFunction privkey(rng,1024);
>
> //...
>
> return 0;
> }
> // Taken from Denis Bider's user guide in the rsa.h section
>
> ...generates this error:
> RSA.cpp: In function `int main()':
> RSA.cpp:15: no matching function for call to
> `CryptoPP::InvertibleRSAFunction::InvertibleRSAFunction
> (CryptoPP::AutoSeededRandomPool &, int)'
> rsa.h:99: candidates are:
> CryptoPP::InvertibleRSAFunction::InvertibleRSAFunction(const
> CryptoPP::InvertibleRSAFunction &)
> rsa.h:99:
> CryptoPP::InvertibleRSAFunction::InvertibleRSAFunction()
>
> It seems that there is no constructor available for these arguments.
Perhaps
> the user guide is getting old with the release of version 5.0 of
> Crypto++5.0??
>
> Anyway I've tried the following instead:
>
> #include "rsa.h"
> #include "osrng.h"
>
> using namespace CryptoPP;
> using namespace std;
>
> int main() {
> AutoSeededRandomPool rng;
> InvertibleRSAFunction privkey; // Just use the default constructor
> privkey.Initialize(rng,1024,17); // Use the Initialize method
>
> return 0;
> }
>
> Now I thought this would work but then I get this error:
> RSA.cpp: In function `int main()':
> RSA.cpp:16: request for member `Initialize' in `privkey', which is of
> non-aggregate type `CryptoPP::InvertibleRSAFunction ()()'
>
> Any hint on what I am doing wrong?
>
> I compiled both samples using:
> g++ -c RSA.cpp -o RSA.o
> g++ -o RSA RSA.o -L. -lcryptopp
>
> compiler: g++ 2.95.4
> uname: Linux zephyr 2.4.19 #1 Thu Oct 24 19:54:10 EDT 2002 i686 AMD
Athlon(TM)
> XP 2000+ AuthenticAMD GNU/Linux
>
> Thanks,
> Jean-Pierre Parent

Reply via email to