|
-
December 22nd, 2010, 10:31 PM
#18
Re: how can i encrypt a file?
 Originally Posted by katy_price
do you mean i have to put my filenames in here
Code:
// Open files:
FileStream ^fInput;
try {
fInput = gcnew FileStream("john.txt", FileMode::Open, FileAccess::Read);
}
catch (...) {
return false;
}
FileStream ^fOutput = gcnew FileStream("can.txt", FileMode::Create, FileAccess::Write);
No. It's easiest to consider the Crypt() function a black-box and leave it unchanged. Instead, you should pass the file names as parameters when you call it:
Code:
if (!Crypt("john.txt", "can.txt", "WhateverPassword", bCryptMode)) {
// Run away and cry...
return 1;
}
Of course you wouldn't hard-code neither the file names nor the password in your actual code but I hope you get the idea.
like i've put john.txt, am i required to have the full path?
That depends on whether the file is located in the current working directory (CWD) of your app or not. If you're not sure it's alway better to use the fully qualified path; that would never do any harm if it's actually not needed.
anyway this is still weird for me how do i serparate the dercyption code from the encryption as they are supposed to be in separate programs.
In the scenario we have here it's not really sensible to separate the encryption and decryption code. The two are so similar that they're best left together in a common function. Whether you actually want to encrypt or decrypt is determined by the bMode parameter you pass to Crypt().
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|