References
External links
Category:Video editing softwareQ:
Converting a sha256 hash of a number and a timestamp
What is the best way of converting a sha256 hash of a number and a timestamp to a timestamp hash?
For example:
timestamp = 1373606851
number = 1315484473
hash = aa3d34f26c1c87bfb3a832d9cfa2cb8c9a0ac8ff78a0189bfad8f7c86d49bf2b
Then what is the best way to convert it to the hash 'aa3d34f26c1c87bfb3a832d9cfa2cb8c9a0ac8ff78a0189bfad8f7c86d49bf2b'?
A:
This is a common problem and there are many libraries which solve it. Here are two of the most used ones:
You can either use one of the above libraries to hash your inputs, then string together the hexdigits. Or you can write your own code to do it. Either way should produce the same result, assuming that no input is corrupted in transit.
Edit 1
Here is the code for the above libraries. The second one was slightly easier to use.
A better solution is to use the library that was designed for the problem. Instead of doing the string building in your code, use the library instead. The library above has a rather vague specification, which makes it hard to use, but the following code is clear and concise. It gives the same results as the library above, but it has less typing:
package main
import "fmt"
// SimpleLeveldbHash returns the SHA-256 hash of the given inputs.
func SimpleLeveldbHash(num uint64, ts time.Time) string {
hash, _ := leveldb.Digest([]byte(fmt.Sprintf("%d", num)), ts)
return hex.EncodeToString(hash[:])
} be359ba680
Related links:
Comments