Chris: Here is a simple snippet of demonstration code I wrote for both Crypto++4.2 and 5.0 (I believe 3.2 uses the same definitions as 4.2). Only the private key comes from a file (also provided), the data comes from the memory array, the public key is derived from the private key (you can save this off to use the key pair in an application). I also have a simple example of sign/verify using this same key.
Hope this helps.
Bob Colestock
#include "rng.h"
#include "des.h"
#include "modes.h"
#include "integer.h"
#include "dh.h"
//#define CRYPTOPP_5_0
#ifndef CRYPTOPP_5_0
#include "cbc.h"
#include "dsa.h"
#endif //CRYPTOPP_5_0
#include "sha.h"
#include "md5.h"
#include "md2.h"
#include "dh2.h"
#include "rsa.h"
#include "rc2.h"
#include "randpool.h"
using namespace CryptoPP;
#include <iostream>
void RWCTest2();
char *lpszPrivateKey="PrivateKey.bin";
RandomPool rndRandom;
unsigned char BufData[]="THIS IS A TEST!!!!!!";
unsigned char signature[2000];
//
//
void RWCTest2()
{
unsigned char pOutCipher[2000];
unsigned char pchDecryptedData[2000];
unsigned int imodulus=0;
//RWC: THIS LOGIC FAILS using Crypto++ 5.0...
CryptoPP::ByteQueue privateKey;
unsigned char BufRSAPrivateKey[2000];
FILE *fp=fopen("./PrivateKey.bin", "rb");
unsigned int iLength = fread(BufRSAPrivateKey, 1, 2000, fp);
fclose(fp);
privateKey.Put(BufRSAPrivateKey, iLength);
RSAES_PKCS1v15_Decryptor rsaPriv(privateKey);
RSAES_PKCS1v15_Encryptor rsaPub(rsaPriv);
rsaPub.Encrypt(rndRandom, BufData, strlen((char *)BufData),
pOutCipher);
#ifndef CRYPTOPP_5_0
imodulus = rsaPub.CipherTextLength(); /*SM_FREE_DEFAULT_KEYBITS /
8;*/
int outLen = rsaPriv.Decrypt(pOutCipher, pchDecryptedData);
#else // CRYPTOPP_5_0
imodulus =
rsaPub.FixedCiphertextLength();//RWC;CiphertextLength(0);
/*RWC;???BASED on key I hope!!!??? */
DecodingResult drResult = rsaPriv.Decrypt(pOutCipher, imodulus,
pchDecryptedData);
int outLen = drResult.messageLength;
#endif // CRYPTOPP_5_0
if (outLen > 0)
std::cout << "RWCTest2: SUCCESSFUL result = |" <<
pchDecryptedData << "|\n";
else
std::cout << "RWCTest2: UN-SUCCESSFUL result, length = " <<
outLen << "\n";
} // END RWCTest2
-----Original Message-----
From: Chris Losinger [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 30, 2003 8:45 PM
To: [EMAIL PROTECTED]
Subject: RSA with Crypto++ v3.1
can anyone give me a simple example of en/decrypting a chunk of
memory
(not a file, please) using RSA, or any other PKE algorithm ?
-c
----
Chris Losinger
[EMAIL PROTECTED]
[EMAIL PROTECTED] http://www.smalleranimals.com
PrivateKey.bin
Description: PrivateKey.bin
