简体   繁体   English

不变数据,散列数据

[英]Unchange Data, hashing data

I want to save some data in a file like .cvs.我想在.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:例如,我的 .csv 中的一行如下所示:

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".如果在这个话题的上下文中使用 google-search,我会经常遇到“散列我的数据”的话题。

How does it work?它是如何工作的?

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 .例如,您可以在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.例如,这就是 git 的工作方式。

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.有时它们带有一个哈希值,您可以自己检查它是否被篡改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM