0

I'm adding encryption functionality to existing program (plain c console app). It takes few files as input parameter and my task is to make this files(sensitive data) secured.

What I do now is that I encrypt the files first (simple XOR with external application), then decipher them back inside the program, the existing program process the files. Then, after everything is successful I encrypt those files back (everything is stored locally on hard disk).

HOWEVER, there is a hole in security, since all the "open" files are stored on hard disk. In case the program fails somewhere in the middle, those files will not be decrypted back.

My problem is that the existing program is taking the FILE variable as input and works directly with those files. It's not my program so I don't have rights to modify it.

What I would need is to write files into memory instead of hard disk. I know that there are some libraries in Linux that enable this, but I develop this in win.

John Conde
  • 217,595
  • 99
  • 455
  • 496
  • The question is not sufficiently clear. Do you need a ramdrive or what else? Please try to clarify a little bit more all the steps of your/external program (using a bullet list for example), one typical use-case, etc. to facilitate who wants to try to give an answer. – Avio Sep 05 '12 at 07:36
  • What I need is to create files inside memory, and work with them as with classic files on hard disk. External program consists of: 1.Function that calls files stored on disk VOID FUNCTION(char *filename) 2.procceses data inside input files – Adam Astar Sep 05 '12 at 07:44
  • What I do now: 1.)encrypt input files (e.g txt files) with XOR 2.)deXOR files inside my module-program that calls external program 3.)external program processes the files 4.decrypt txt file back inside my module – Adam Astar Sep 05 '12 at 07:58

1 Answers1

0

The FILE data type is used to obtain a file pointer to the file being opened, so your FILE * variable is already in memory. If you want the whole file in memory, then you have to allocate a buffer with the same size of your file and read the whole file in memory.

On Stackoverflow you can find more examples about fread, fwrite, fseek and so on.

EDIT:

If you want to manipulate files in memory, but using the existing stdio.h interfaces (fopen, fread, fwrite, etc.) you need a ramdrive. Here you can find some free driver to make it on Windows. Remember that you have to move files inside the ramdrive to process them, and move them outside the ramdrive when you have finished, or all your changes will be lost.

Community
  • 1
  • 1
Avio
  • 2,700
  • 6
  • 30
  • 50
  • From the OP's comment itlooks like the API is using `char * filename` to reference the file rather then `FILE *`. – alk Sep 05 '12 at 08:07
  • In the question he says that his external program is using `FILE` variables to manipulate files. However with a ramdrive, it doesn't matter anymore _how_ a programm access files. The ramdrive provides a transparent access to them in main memory. – Avio Sep 05 '12 at 08:12
  • Thanks for answers, I can read the whole file and put data from file to buffer and process it in the buffer indeed,but then I will be forced to write data back into some file, since external program that I don't own and cannot edit, is working only with files. Final product will be used by clients and I cannot imagine how it will work with Ramdisk. Thanks a lot anyway – Adam Astar Sep 05 '12 at 08:12