3 ms·
Yes. I don't have an immediate reference, but I've seen this situation addressed in may tutorials concerning properly salting passwords. The general rule of t
by johnhenry 9y ago
Yes.
I don't have an immediate reference, but I've seen this situation addressed in may tutorials concerning properly salting passwords.
The general rule of thumb is to not serialize and hash data this way precisely because of the risk of collision that you have outlined.
I believe that something more along the lines of
createHash('SHA256').update(timestamp).update(data).update(index).update(previousHash)
though, that isn't a complete fix.
- ctz 9y agoThis code is equivalent.
- johnhenry 9y agoNot entirely... Depending upon the types of "timestamp", "data", "index", and "previousHash", the value, "timestamp+data+index+previousHash", may be interpreted as a number or a string, affecting the final hash. Splitting it up prevents this uncertainty.