Thread: Best way to do encryption file stream

  1. #1
    Registered User Xeridanus's Avatar
    Join Date
    Oct 2006
    Location
    QLD, Aussieland
    Posts
    11

    Best way to do encryption file stream

    this is prolly an advanced problem, im not sure.

    i have created a program in C++ for encrypting files. you can either pass it command line arguments in which case it will run silently or if a dumb user stumbled upon it they would be given prompts to figure out how it works.

    there is nothing wrong with that program it works fine, my question is what would be the best way to go about converting that into a way of encrypting data on it's way out of a program, in the exact same way as you would output to any normal file. in essence, an encrypted file stream class.

    Thank you for your time.

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Perhaps make main a function, which would get a string, run the encryption process, then output that string in the function to the file:
    Code:
    encrypt_ofstream (string& encrypt)
    {
        run your encrypting process;
        open file and fout; 
    }
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Registered User Xeridanus's Avatar
    Join Date
    Oct 2006
    Location
    QLD, Aussieland
    Posts
    11
    yes, but i would like it to behave in the same way as the file streams, using overloaded << and >> operators. i was wondering if anyone could tell me if it would be better to derive my class from the stream class that all other streams derive from (can't remember the name) or if it would be better to use the ofstream and ifstream inside my class.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Look at Boost.Iostreams. Use a filter to implement the encryption.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User Xeridanus's Avatar
    Join Date
    Oct 2006
    Location
    QLD, Aussieland
    Posts
    11
    hey thanks. this looks like it can do exactly what i want.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM