-
November 15th, 2014, 09:17 AM
#1
crypt a file [algorithm]
Hello, I am trying to make a basic crypting program, you simply input a file and it's crypted using ECIES.
So I use cryptopp, ( see the function : http://www.cryptopp.com/wiki/Ellipti...ryption_Scheme ).
So I thought I just needed to open the files and crypt the content like that :
Code:
file = "lorem.txt"
std::ifstream if1s(file);
std::string content((std::istreambuf_iterator<char>(if1s)), std::istreambuf_iterator<char>());
if1s.close();
ofstream myfile1;
myfile1.open(file);
myfile1 << encrypt(content);
myfile1.close();
encrypt is a custom made function to make encryption simplier here is the header :
Code:
string encrypt(string message);
This works pretty well on text files but when I try to crypt a 1 mb image, the output is 0.5 kb which obviously can't be right, so I wonder if there is some specific way to crypt some files.
Thanks in advance
-
November 17th, 2014, 07:42 AM
#2
Re: crypt a file [algorithm]
an std::string ends at a binary zero, which is very likely to occur in a binary file like an image.
you need to load the data into a vector/buffer, and pass that to the encryption instead of using a string.
also note that there are encryptions that are only suited to handle text. so you may also need to convert the binary into text via some encoding system like uuencode/base64/...
-
November 17th, 2014, 08:15 AM
#3
Re: crypt a file [algorithm]
1) You need to open the file as binary. Otherwise, if an EOF character is encountered, input will stop.
2)
Originally Posted by OReubens
an std::string ends at a binary zero, which is very likely to occur in a binary file like an image you need to load the data into a vector/buffer, and pass that to the encryption instead of using a string.
std::string can handle embedded NULLS.
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
|