The byte type in Java is signed, it has a range of -128..127 , and in Go byte is an alias of uint8 and has a range of 0..255 . Therefore, if you want to compare the results, you need to shift the negative Java values by 256 (add 256 ).
Tip. To display the Java byte value in unsigned form, use: byteValue & 0xff , which converts it to int , using 8 byte bits as the lower 8 bits in int . Or better: display both results in hexadecimal so that you don't have to worry about the sign ...
Adding 256 to your negative Java byte values, the result is almost identical to Go: the last byte is turned off by 1:
javabytes := []int{83, -116, -9, -98, 115, -126, -3, -48} for i, b := range javabytes { if b < 0 { javabytes[i] += 256 } } fmt.Println(javabytes)
Output:
[83 140 247 158 115 130 253 208]
So, the last byte of your Java array is 208 , and Go is 207 . I assume that your counter incremented once in another place in your code that you have not yet submitted.
What makes Java different is that you return a hexadecimal result, while in Go you return a Base64 encoded result (these are two different encodings giving completely different results). As you have confirmed, in Go returning hex.EncodeToString(h.Sum(nil)) , the results are the same.
Tip # 2: To display Go bytes in signed form, just convert them to int8 (which is signed) as follows:
gobytes := []byte{83, 140, 247, 158, 115, 130, 253, 207} for _, b := range gobytes { fmt.Print(int8(b), " ") }
It is output:
83 -116 -9 -98 115 -126 -3 -49