encrypt filenames program



can anyone tell me why this program doesn't work if you give filenames
with a "space line space".. like
file - 2005.bzip

here it is:

#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::DEFAULT_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::Decryption blowDe((unsigned char*)key.c_str(),
key.size());
CBC_Mode_ExternalCipher::Decryption 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());

.



Relevant Pages

  • Re: Security implications of using open() on untrusted strings.
    ... Jorgen Grahn wrote: ... regexery however I would like to check filenames and I would like this ... Although it's a desktop app I'm a little squeamish ... Compare with a language where if the string ...
    (comp.lang.python)
  • Re: Extracting patterned filenames from [glob] without a loop - possible?
    ... > obtain the correct pattern to make it work. ... A couple obvious problems relate to the fact you are using string ... This is relatively safe since lists can easily be converted ... filenames without 'horrifcally clogging' a system. ...
    (comp.lang.tcl)
  • Re: Security implications of using open() on untrusted strings.
    ... regexery however I would like to check filenames and I would like this ... Although it's a desktop app I'm a little squeamish ... piping raw user input into a filesystem function like that and this app ... Compare with a language where if the string ...
    (comp.lang.python)
  • Re: How can I make a copy of my collection?
    ... Public Class FileNames ... Public fullName As String ... This app is simply to help me try to conform some of the files names ... And then even sub folders for file types. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How to determine which process to kill ???
    ... >the filenames that were used, like, in a string array or something: ... >Private Function createTempFile() As String ... >some system related process or Windows Service or your AntiVirus agent. ...
    (microsoft.public.dotnet.languages.vb)