It takes a string, converts it to a byte array, runs an sha256 hash on it,
then converts the hash to a base64 encoded string.
There seems to be some sort of problem in that the value I get out is not
the same value I get from making the same calculation using external tools.
The value is consistent at least and appears to be cascading when I change
the input, but it's small comfort because it doesn't match the
independently calculated values at all.
Here is some code, hopefully someone can let me know if I'm doing something
wrong, or maybe just calculating the expected output incorrectly...
given
func HashIt(in string) string {
hasher := sha256.New()
hasher.Write([]byte(in))
out := base64.URLEncoding.EncodeToString(hasher.Sum(nil))
return out
}
With test case...
func main() {
in := "The quick brown fox, jumped over the lazy dog!"
out := hashing.HashIt(in)
fmt.Printf("in: %+v \t out: %+v\n", in, out)
}
I'm getting...
in: The quick brown fox, jumped over the lazy dog! out:
GJ31mY7s2N86FJJ4iddQr0GPUK7e9xDDrBHVunZHLrk=
But I'm expecting out to be ...
MTg5ZGY1OTk4ZWVjZDhkZjNhMTQ5Mjc4ODlkNzUwYWY0MThmNTBhZWRlZjcxMGMzYWMxMWQ1YmE3NjQ3MmViOQ
==
The expected result was calculated by using the SHA256 tool at
http://www.xorbin.com/tools/sha256-hash-calculator and then pasting the
output into it's corresponding Base64 encoder at
http://www.xorbin.com/tools/base64-encoder-and-decoder
Thanks for your help/advice.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.