Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Can anyone point me to a strong algorithm I can use to encrypt and decrypt data in a random access file?

I need to be able to update entries without having to rewrite the whole file and only read the parts that I need; I think this could exclude a lot of stream cyphers.
Posted
Comments
Sergey Alexandrovich Kryukov 9-Oct-14 12:00pm    
This is not a well-defined question. You need to understand and indicate your security schema. Open-key or symmetric? who deploys what, encrypts what and who decrypts, based on what?
—SA
Nagy Vilmos 9-Oct-14 12:19pm    
Correct, because as it stands I'm looking for ideas. I'm not after a /this is the right and true way/ I want ideas so that I can go off and fup things.
Sergey Alexandrovich Kryukov 9-Oct-14 13:11pm    
Please see my answer.

If you have problems with encryption, first study the topic (Wikipedia would be enough), then ask your questions. Remember, you can have true read/write, of the O(1) complexity, only if you have fixed structure. With non-fixed positions, you can have O(1) on read and O(x) on write? why? because eventually you would need to change the file size by inserting in the middle and shifting the rest of file down. This design is achieved by having a fixed-structure record table (say, binary table record#-record_location). Is it clear? Decide on your preferences...

—SA

1 solution

Please see my comment to the question.

The idea is: you need to modify the structure of your file. It can be composed of the set of encrypted fragment. For random access, it would be good to have fixed-size (in encrypted form) fragments, but encrypted algorithms are well suited for that. This way, you can seek the file position on a fragment and decrypt it all, modify and write to the same place. If you do it, I would highly recommend to use binary form; it would be much simpler.

—SA
 
Share this answer
 
Comments
CPallini 9-Oct-14 13:46pm    
Right, my 5. At least he could divide is (supposing) text file in blocks corresponding to the ones required by the encryption algorithm.
Sergey Alexandrovich Kryukov 9-Oct-14 13:55pm    
Thank you, Carlo.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900