hi,
i think its a newbie question - i am a newbie.
i want to encrypt and decrypt strings for a lan-connection. so i
tried to split setkey, encrypt and decrypt. the key will be the same for the
whole seesion. it works fine after starting but after 3-15 rounds the
strings will be shorter and wrong. i´m nor sure about Padding
and MessageEnd().
anyone who can help.
thanks a lot.
testmain:
...
char cPlainText[] = "what ever i want to DeOrEncrypt";
Crypt scs;
scs.TwofishSetKey(key, sizeof(key), iv);
for(int i = 0; i< 10000; i++) { // test
scs.TwofishEncrypt(cPlaintext);
scs.TwofishDecrypt(cPlaintext);
}
...
class Crypt:
...
SymmetricCipher *cbcEncryption, *cbcDecryption;
StreamTransformationFilter *cbcEncryptor, *cbcDecryptor;
std::string
strEncrypted, strDecrypted;
...
void Crypt::TwofishSetKey(unsigned
char *key, int keySize, unsigned char *iv)
{
cbcEncryption = new CFB_Mode<Twofish>::Encryption(key, keySize, iv);
cbcEncryptor = new StreamTransformationFilter(*((SymmetricCipher*)cbcEncryption),
new StringSink(strEncrypted), StreamTransformationFilter::NO_PADDING);
cbcDecryption = new CFB_Mode<Twofish>::Decryption(key, keySize, iv);
cbcDecryptor = new StreamTransformationFilter(*((SymmetricCipher*)cbcDecryption),
new StringSink(strDecrypted), StreamTransformationFilter::NO_PADDING);
}
void Crypt::TwofishEncrypt(char* Sequence)
{
cbcEncryptor->Put((byte *)Sequence, (unsigned int)strlen(Sequence));
memcpy(Sequence, strEncrypted.c_str(), strEncrypted.size());
strEncrypted.erase();
}
void Crypt::TwofishDecrypt(char* Sequence)
{
cbcDecryptor->Put((byte *)Sequence, (unsigned int)strlen(Sequence));
memcpy(Sequence, strDecrypted.c_str(), strDecrypted.size());
strDecrypted.erase();
}
...