can anyone tell me why this c++ code works encrypting simple filenames
but instead if you try to encrypt a filename like "video - 833 12_
..avi" it doesn't rename the file??????
#include <fstream>
#include <iostream>
//cryptopp libraries
#include <cryptopp/osrng.h> //needed for AutoSeededRando mPool
#include <cryptopp/modes.h>
#include <cryptopp/blowfish.h>
#include <cryptopp/filters.h>
using namespace std;
using namespace CryptoPP;
int main()
{
cout<<"//////////////////////////////"<<endl;
cout<<"rename with filename encryption/decryption"<<en dl;
cout<<"CTRL+C to exit"<<endl;
cout<<"//////////////////////////////"<<endl;
//ENCRYPT FILENAME
string infilename;
string outfilename;
cout <<"Enter filename of file to encrypt or decrypt: ";
cout<<"\n";
cin >>infilename;
cout<<"\n";
ifstream input(infilenam e.c_str());
AutoSeededRando mPool rng;
string key(Blowfish::D EFAULT_KEYLENGT H, 0);
string iv(Blowfish::BL OCKSIZE, 0);// this is the Initialization
Vecktor
cout<<"enter the password..(12 charachters max)"<<endl;
cout<<"\n";
cin>>key;
iv="àc€*Õ=Xòžy" ; //default block
cout<<"Do you want to encrypt 1 \nor to decrypt 0 \n?";
int choice;
cin>>choice;
if (choice)
{
//Setup the Blowfish Cipher in CBC-Mode
Blowfish::Encry ption blowEn((unsigne d char*)key.c_str (),
key.size());
CBC_Mode_Extern alCipher::Encry ption cbcEn( blowEn, (unsigned
char*)iv.c_str( ) );
//Put the "plain" string into the cipher and encrypt it to
"encrypted
StreamTransform ationFilter stfEncryptor(cb cEn, new StringSink(
outfilename ) );
stfEncryptor.Pu t( (unsigned char*)infilenam e.c_str(),
infilename.size () + 1 );
stfEncryptor.Me ssageEnd();
}
else
{
// Decrypt (very analog to the encryption block
Blowfish::Decry ption blowDe((unsigne d char*)key.c_str (),
key.size());
CBC_Mode_Extern alCipher::Decry ption cbcDe( blowDe, (unsigned
char*)iv.c_str( ) );
StreamTransform ationFilter stfDecryptor(cb cDe, new StringSink(
outfilename ) );
stfDecryptor.Pu t((unsigned char*)infilenam e.c_str(),
infilename.size () );
stfDecryptor.Me ssageEnd();
}
cout<<"renaming to..."<<outfile name<<endl;
rename(infilena me.c_str(),outf ilename.c_str() );
}