473,395 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

encrypt filenames debug

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::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());

}

Mar 10 '06 #1
2 3020
ri*****@email.com wrote:
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?????? [snip] rename(infilename.c_str(),outfilename.c_str());


Maybe it has something to do with the fact that the filename has spaces
in it. Perhaps you need to surround the filename with quotes.

--
Marcus Kwok
Mar 10 '06 #2
actually it seems working for:
a - 4.bzip
a-k.bzip
a.zip
aaaaaaaaaaa.bzip
ajehkwhferfuiwefhkwehfhweifhwfwkl.bz2

but not for:
a - l.zip

just like as if the combination of "space line space" confuused the
proram... and no.. putting " hypens " before and after the filename
didn't help...

if someone can compile it here's how to do it:

first install cryptolib from site
http://www.eskimo.com/~weidai/cryptlib.html or urpmi libcrypto
you need the development package, which contains also the header files.
In "urpmi" I guess this package is named "libcryptopp5-dev",
"...-devel" or something like this. Then your package manager will most
usually create a link to the actual library. In example if the library
is named "libcryptopp5.0.2.a" (I guess this will be true for you), it
will create a link named "libcryptopp.a" that points to this file.
Similiar is true for the dynamic libraries in your output above
(libcryptopp.so.5.0.2 is usually just link to libcryptopp.so.5,
although we don't use it here). But if you hava a file "libcryptopp.a",
then you link against it with:
Code:

g++ -lcryptopp sourceFile.cpp

About the includes:
The easiest way to find out, where the headers were installed to, is by
just searching for them. In my case I used (for example) the file
"blowfish.h", so:
Code:

cd /usr find -name blowfish.h

If I do this on my system, it shows me, that it is in
"/usr/include/crypto++/". Because "/usr/include" is one of the default
include paths, I can include the file with:
Code:

#include <crypto++/blowfish.h>

If, for example, on your machine the crypto-headers are located in
"/no/default/includes/cryptopp", then you have to include it this way:
Code:

#include "/no/default/includes/cryptopp/blowfish.h"

Or another way would be:
Code:

#include <cryptopp/blowfish.h>

....but then you have to invoke the compiler like so:
Code:

g++ -lcryptopp -I/no/default/includes sourceFile.cpp

Mar 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: wqhdebian | last post by:
As far as I know,when encrypt or decrypt ,a key must first be got,and the key is first generate by a tool or from SecurityRandom,that means I can not generate the same key with the same input.Does...
5
by: Mark | last post by:
How can I populate a listbox with a list of the filenames in a certain folder? Can a query retrieve the filenames from a folder? Thanks! Mark
8
by: Gidi | last post by:
Hi, Is there Buid-In fuction in C# that Encrypt and Decrypt strings? i have a textbox which i'm writing into file, and i want to encrypt it before writing, i'm not looking for something fancy,...
2
by: rbutch | last post by:
guys, i need a little help with this. this is working (well sort of) i get the info, but it's not moving to a new line as it iterates thru the array and all of the fields are like ONE HUGE LONG...
0
by: Mike | last post by:
We want to use FormsAuthenticationTickets as part of our ASP.NET security. The current design stores the user's ticket in the db, and later uses the ticket to extract other data from the database....
0
by: n33470 | last post by:
We have a web site that is being converted from the 1.1 format into 2.0. I've noticed that after the web project has been converted, the first time that the solution is opened in VS, all of the...
9
by: sweety | last post by:
Dear All, How to encrypt a C data file and make binary file and then have to read a bin file at run time and decrypt the file and have to read the data. Any help to achive this pls. Would be...
4
by: Tom | last post by:
Is it possible to encrypt a value in the my.settings area in VB.NET 2005? I.E. Can I add a settings value (via My Project / Settings) and have it encrypt that value so that if anyone looks at the...
0
by: chongming | last post by:
Hi, i want to display all the filenames on browser. However i found that if there are many filenames in that folder, result will be it will display a long list of filenames on that browser. My...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.