On Mon April 27 2009, AngelWarrior wrote: > I have a file containing 549 bytes of data. When I try to encrypt the data,I > get only a partial encrypted data in the range of 113 to 140 bytes in > different runs.When I decrypt the data I get the partial data. > > This is a QT application OpenSSL 0.9.8j windows > > int main(int argc, char** argv ) > { > > QApplication app(argc , argv); > QFile inputfile("input.xml"); > stin.open(stdin ,QIODevice::ReadOnly); > stout.open(stdout,QIODevice::WriteOnly); > > outLine("Enter key\n"); > QString key=readIn(); > inputfile.open(QIODevice::ReadOnly); > QByteArray temp = inputfile.readAll(); > BF_KEY ks; > BF_set_key( &ks, key.length(), (const unsigned > char*)(key.toAscii().data())); > > char ivec[8]; > memset(ivec,0,8); > int num=0; > > char *out = new char[temp.length()]; > > BF_cfb64_encrypt((unsigned char*)temp.data(), (unsigned char*)(out), > (unsigned long)temp.length(), &ks, (unsigned char*)ivec, &num, > BF_ENCRYPT ); > > > outLine("Encrypted Data\n"); > outLine("-----------------------------------------------\n"); > outLine(QString().sprintf("Encrypt length = %d\n",strlen(out))); > outLine(QString(out)); > outLine("\n"); > > readIn(); > > QFile outputfile("output.xml"); > outputfile.open(QIODevice::WriteOnly); > outputfile.write(out,strlen(out)); > > > QByteArray entemp(out); > memset(out,0,temp.length()); > memset(ivec,0,8); > num=0; > //out = new char[entemp.length()]; > > BF_cfb64_encrypt((unsigned char*)entemp.data(), (unsigned char*)(out), > (long)entemp.length(), &ks, (unsigned char*)ivec, &num, > BF_DECRYPT ); > > outLine("Decrypted Data\n"); > outLine("-----------------------------------------------\n"); > outLine(QString().sprintf("Decrypt length = %d\n",strlen(out)));
Encrypted data != C-string format; \0 is a legal data value, not a string terminator. > outLine(QString(out)); > } > > -------------------------------------------------------- > Enter key > temp > Encrypted Data > ----------------------------------------------- > Encrypt length = 180 > ?ƒ6i[y╔╒⌂+ñßh÷≥┴W¿┼XE╕û─ºæ▓iÜ║↑┴K♦8)zⁿö♠j⌐┤▐⌡ë┐FMG╡^δå,♀p[⌐«╥∞Aεën > u%↑&Aƒ╖½1Φ║÷;α┘╦▬á▼]q{ █}╕9b▌$Åp╗▐D½k?ε/ôH(☺ªuÑ↓ñ╖¿jåHV┘¥zεφ│wc > ╙l■d▲▀¿úu1╜iPα > > Decrypted Data > ----------------------------------------------- > Decrypt length = 180 > <input> > <name>hello how are you doing</name> > <sunday>yes</sunday> > <monday>no</monday> > <tuesday>no</tuesday> > <wednesday>no</wednesday> > <thursday>no</thursday> > <friday>no</fri ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org