Hello everybody.
I am doing Symmetric Encryption of a plain text buffer using 2 different methods, and the results are different... why?
Actually the encryption work's well but the decryption does not work.
See the example following:
#include "stdio.h" #include "stdlib.h" #include "time.h"
#include "cryptopp/dll.h" using namespace CryptoPP; #pragma comment (lib,"cryptoppd")
int main(int argc, char* argv[])
{
UCHAR plain[] = "test message";
UCHAR out_plain[sizeof(plain)];
UCHAR chiper[sizeof(plain)];
UCHAR chiper2[sizeof(plain)];
UCHAR key[DES::DEFAULT_KEYLENGTH];
UCHAR iv[DES::BLOCKSIZE];
unsigned bSize = strlen((char*)plain); srand(time(0));
for(int i=0;i<DES::DEFAULT_KEYLENGTH;i++)
key[i] = rand()%256;
for(i=0;i<DES::BLOCKSIZE;i++)
iv[i] = rand()%256;{ //THIS PART RUN'S FINE!!!
DES::Encryption desEncryption(key, DES::DEFAULT_KEYLENGTH);
CFB_Mode_ExternalCipher::Encryption cfbEncryption(desEncryption, iv);
DES::Encryption desDecryption(key, DES::DEFAULT_KEYLENGTH);
CFB_Mode_ExternalCipher::Decryption cfbDecryption(desDecryption, iv);
cfbEncryption.ProcessData(chiper, plain,bSize);
cfbDecryption.ProcessData(out_plain, chiper,bSize);
}
{ //THIS PART DOES NOT WORK!!!
//even if it should be the same as previous...
//encrypt work's ok the chiper and chiper2 is equal, but the out_plain is different!
DES::Encryption *chpEnc = new DES::Encryption(key, DES::DEFAULT_KEYLENGTH);
CFB_Mode_ExternalCipher::Encryption *cfbEncrypt
= new CFB_Mode_ExternalCipher::Encryption(*chpEnc, iv);
DES::Decryption *chpDec = new DES::Decryption(key, DES::DEFAULT_KEYLENGTH);
CFB_Mode_ExternalCipher::Decryption *cfbDecrypt
= new CFB_Mode_ExternalCipher::Decryption(*chpDec, iv);
cfbEncrypt->ProcessData(chiper2, plain, bSize);
cfbDecrypt->ProcessData(out_plain, chiper2, bSize);
delete cfbEncrypt;
delete cfbDecrypt;
delete chpEnc;
delete chpDec;
}
return 0; }
