473,756 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

}

Mar 10 '06 #1
2 3046
ri*****@email.c om 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(infilena me.c_str(),outf ilename.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.bzi p
ajehkwhferfuiwe fhkwehfhweifhwf wkl.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 "libcryptop p5-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 "libcryptop p.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
7958
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 there is a method which can generate a same with the same input string? There is a need to transfer file between to site,and the customer wish to encrypt these files during transfering,and they want to store a string into each database at...
5
17137
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
8184
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, just for a simple Encryption and Decryption function. thanks, Gidi.
2
8671
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 string 'declare an array Dim filenames() As String filenames = Directory.GetFiles("C:\Re_Class") Dim i, o As Integer Dim info As String
0
1303
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. When the user logs out, we use the ticket to delete the ticket from the db, using the encrypted ticket as the key. Problem is, the tickets don't seem to match between being encrypted and then decrypted. For example, the following returns two...
0
1397
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 aspx and ascx filenames are changed to lowercase. The filenames are not being changed during the conversion process. After conversion completes, the filenames remain unchanged. However, the first time that the solution is opened in VS2005, the...
9
5163
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 great if any sample source code provided. Thanks, Sweety
4
10842
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 resulting app.config file the value is encrypted? If so, (1) How do you specify the value to be encrypted? And (2) How do you access it now from VB? Can you still go through My.Settings?? Tom --
0
2509
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 question is how do i iterate the file names with 5 filenames on each page? I have manage to retrieve and display the filenames with the codes below. Can anyone help me or give advice on how to do the iteration? The codes are below and able to...
0
9287
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9886
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9722
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7259
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.