As I told you, to encrypt with your private key would be easy.
What you should do in order to do this is modifying the GenerateRSAKey method the following way:
 
replace line:
    priv.DEREncode(privFile);
with:
    RSAES_OAEP_SHA_Encryptor shorterPriv(priv);
    shorterPriv.AccessKey().SetPublicExponent(priv.GetKey().GetPrivateExponent());
    shorterPriv.DEREncode(privFile);
 
Adrian

----- Original Message -----
From: "MrWebLover" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, April 06, 2004 1:58 PM
Subject: Re: RSA Public Key Encryption ---> Antivir4QMail checked <---

> Thank you for your answers.
>
> @ Ludwig Seiz
>
> This was my first test, to change the private and public key's ...
>
> But it dosn't work !
>
> The program end's with an 'Debug Error !' --> 'Abnormal Program Termination'
> at the point
>
> RSAEncryptString("privkey.txt", "Testseed", plain.data());
>
> Is there a trick, to change the key's ????
>
> I hope you can help me, to find a solution for encrypt with the private and
> decrypt with the public key.
> This would be the best solution for me .....
>
> Thank you, for your help !!
>
> best regards,
>
> Torsten
>
>
> Here is my Testprogram :
>
> // mytest.cpp
> //
>
> #include "stdafx.h"
>
> #include "cryptlib.h"
> #include "randpool.h"
> #include "sha.h"
> #include "rsa.h"
> #include "hex.h"
> #include "files.h"
> #include "elgamal.h"
> #include "pubkey.h"
> #include "validate.h"
> #include "randpool.h"
>
> #include "pkcspad.h"
> #include "oaep.h"
> #include "integer.h"
> #include "asn.h"
>
> using namespace std;
> using namespace CryptoPP;
>
>
> RandomPool & GlobalRNG()
> {
>  static RandomPool randomPool;
>  return randomPool;
> }
>
>
>
> void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const
> char *pubFilename, const char *seed)
> {
>  RandomPool randPool;
>  randPool.Put((byte *)seed, strlen(seed));
>
>  RSAES_OAEP_SHA_Decryptor priv(randPool, keyLength);
>  HexEncoder privFile(new FileSink(privFilename));
>  priv.DEREncode(privFile);
>  privFile.MessageEnd();
>
>  RSAES_OAEP_SHA_Encryptor pub(priv);
>  HexEncoder pubFile(new FileSink(pubFilename));
>  pub.DEREncode(pubFile);
>  pubFile.MessageEnd();
> }
>
> string RSAEncryptString(const char *pubFilename, const char *seed, const
> char *message)
> {
>  FileSource pubFile(pubFilename, true, new HexDecoder);
>  RSAES_OAEP_SHA_Encryptor pub(pubFile);
>
>  RandomPool randPool;
>  randPool.Put((byte *)seed, strlen(seed));
>
>  string result;
>  StringSource(message, true, new PK_EncryptorFilter(randPool, pub, new
> HexEncoder(new StringSink(result))));
>  return result;
> }
>
> string RSADecryptString(const char *privFilename, const char *ciphertext)
> {
>  FileSource privFile(privFilename, true, new HexDecoder);
>  RSAES_OAEP_SHA_Decryptor priv(privFile);
>
>  string result;
>  StringSource(ciphertext, true, new HexDecoder(new
> PK_DecryptorFilter(GlobalRNG(), priv, new StringSink(result))));
>  return result;
> }
>
>
> int main(int argc, char* argv[])
> {
>  string plain = "This is the text to encrypted";
>  string strenc;
>  string strdec;
>
>  GenerateRSAKey( 1024, "privkey.txt", "pubkey.txt", "Testseed");
>
>  printf("Plain : %s\n\n", plain.data());
>
>  strenc = RSAEncryptString("privkey.txt", "Testseed", plain.data());
>
>  printf("Encrypted : %s\n\n", strenc.data());
>
>  strdec = RSADecryptString("pubkey.txt", strenc.data());
>
>  printf("Decrypted : %s\n\n", strdec.data());
>
>  return 0;
> }
>
>

Reply via email to