• PROBLEM :I had been trying to encrypt and decrypt data using RSA algorithm it works well till 80 characters but after that it shows abnormal program termination
  • exact error message :Abnormal program Termination
  • Code Sample:
  • #include "pch.h"
    #include "md5.h"
    #include "sha.h"
    #include "ripemd.h"
    #include "files.h"
    #include "rng.h"
    #include "hex.h"
    #include "gzip.h"
    #include "default.h"
    #include "rsa.h"
    #include "randpool.h"
    #include "ida.h"
    #include "base64.h"
    #include "socketft.h"
    #include "dsa.h"
    #include "rsa.h"
    #include "osrng.h"
    #include "wait.h"
    #include "fips140.h"

    #include "validate.h"
    #include "bench.h"

    #include <iostream>
    #include <time.h>

    #if defined(_WIN32) || defined(__CYGWIN__)
    #include <windows.h>
    #endif

    #if (_MSC_VER >= 1000)
    #include <crtdbg.h>  // for the debug heap
    #endif

    #if defined(__MWERKS__) && defined(macintosh)
    #include <console.h>
    #endif

    USING_NAMESPACE(CryptoPP)
    USING_NAMESPACE(std)

    const int MAX_PHRASE_LENGTH=250;

    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(priv, new StringSink(result))));
     return result;
    }

    void main() {

      char seed[1024], privFilename[128], pubFilename[128];
      unsigned int keyLength;
      char message[1024];

      cout << "Key length in bits: ";
      cin >> keyLength;


      cout << "\nSave private key to file: ";
      cin >> privFilename;

      cout << "\nSave public key to file: ";
      cin >> pubFilename;

      cout << "\nRandom Seed: ";
      ws(cin);
      cin.getline(seed, 1024);

      cout<< "\nRandom Seed:1 " << seed;
      GenerateRSAKey(keyLength, privFilename, pubFilename, seed);
      cout<< "\nRandom Seed:2 " << seed; 
      // char privFilename[128], pubFilename[128];
      // char seed[1024], message[1024];

      // cout << "Private key file: ";
      // cin >> privFilename;

      // cout << "\nPublic key file: ";
      // cin >> pubFilename;

      // cout << "\nRandom Seed: ";
      // ws(cin);
      // cin.getline(seed, 1024);

      cout << "\nMessage: ";
      cin.getline(message, 1024);

      cout<< "\nRandom Seed:3 " << seed; 
      string ciphertext = RSAEncryptString(pubFilename, seed, message);
      cout<< "\nRandom Seed:4 " << seed; 
      cout << "\nCiphertext: " << ciphertext << endl;

      string decrypted = RSADecryptString(privFilename, ciphertext.c_str());
      cout << "\nDecrypted: " << decrypted << endl;
    }

    Compiler And Platform Used :Windows(2000) ,crypto++ ver 5and VC++ compiler

    I will be very thankful if anyone can help me out

    Regards,

    Shawn

     

     



    Do you Yahoo!?
    Yahoo! Tax Center - forms, calculators, tips, and more

    Reply via email to