Unchange Data, hashing data

48 views Asked by At

I want to save some data in a file like .cvs. One of the condition is, that the data can't change after write in the file. If I want to read the data, it should be save that the data were not change in the past and I want to get an alert, if the data changed in the past by other.

For example a line in my .csv looks like this:

34, 234, test, monday, peter

How can I check, that line changed by somebody?
How can I lock, that nobody changed one of my lines?

I hope you know what I mean. If use google-search in context of this topic, I will often meet the topic of "hashing my data".

How does it work?

1

There are 1 answers

0
bleonard On

Hashing is the concept of taking a lot of data and reducing to a single (much smaller) string or number. So, there are various algorithms that would take the whole file and come up with a hash. For example, here is how you might do that in Node.

The most important aspect of the algorithm is that if the contents change in any way, then the hash will also change. This is how git works, for example.

So, what you could do it hash that file and save the resulting string somewhere and then compare the results later. You may have seen this is installer downloads over the years. Sometimes they come with a hash that you could check yourself to see if it's been tampered with.