R
rino100
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 AutoSeededRandomPool
#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"<<endl;
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(infilename.c_str());
AutoSeededRandomPool rng;
string key(Blowfish:EFAULT_KEYLENGTH, 0);
string iv(Blowfish::BLOCKSIZE, 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::Encryption blowEn((unsigned char*)key.c_str(),
key.size());
CBC_Mode_ExternalCipher::Encryption cbcEn( blowEn, (unsigned
char*)iv.c_str() );
//Put the "plain" string into the cipher and encrypt it to
"encrypted
StreamTransformationFilter stfEncryptor(cbcEn, new StringSink(
outfilename ) );
stfEncryptor.Put( (unsigned char*)infilename.c_str(),
infilename.size() + 1 );
stfEncryptor.MessageEnd();
}
else
{
// Decrypt (very analog to the encryption block
Blowfish:ecryption blowDe((unsigned char*)key.c_str(),
key.size());
CBC_Mode_ExternalCipher:ecryption cbcDe( blowDe, (unsigned
char*)iv.c_str() );
StreamTransformationFilter stfDecryptor(cbcDe, new StringSink(
outfilename ) );
stfDecryptor.Put((unsigned char*)infilename.c_str(),
infilename.size() );
stfDecryptor.MessageEnd();
}
cout<<"renaming to..."<<outfilename<<endl;
rename(infilename.c_str(),outfilename.c_str());
}
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 AutoSeededRandomPool
#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"<<endl;
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(infilename.c_str());
AutoSeededRandomPool rng;
string key(Blowfish:EFAULT_KEYLENGTH, 0);
string iv(Blowfish::BLOCKSIZE, 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::Encryption blowEn((unsigned char*)key.c_str(),
key.size());
CBC_Mode_ExternalCipher::Encryption cbcEn( blowEn, (unsigned
char*)iv.c_str() );
//Put the "plain" string into the cipher and encrypt it to
"encrypted
StreamTransformationFilter stfEncryptor(cbcEn, new StringSink(
outfilename ) );
stfEncryptor.Put( (unsigned char*)infilename.c_str(),
infilename.size() + 1 );
stfEncryptor.MessageEnd();
}
else
{
// Decrypt (very analog to the encryption block
Blowfish:ecryption blowDe((unsigned char*)key.c_str(),
key.size());
CBC_Mode_ExternalCipher:ecryption cbcDe( blowDe, (unsigned
char*)iv.c_str() );
StreamTransformationFilter stfDecryptor(cbcDe, new StringSink(
outfilename ) );
stfDecryptor.Put((unsigned char*)infilename.c_str(),
infilename.size() );
stfDecryptor.MessageEnd();
}
cout<<"renaming to..."<<outfilename<<endl;
rename(infilename.c_str(),outfilename.c_str());
}