CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: crypt a file [algorithm]

  1. #1
    Join Date
    Nov 2014
    Posts
    7

    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

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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/...

  3. #3
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,716

    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)
    Quote Originally Posted by OReubens View Post
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)