I'm trying to generate hash with same algorithm (sha256) for same input in Java and Go. Interestingly I'm getting two values. Any Explanation is appreciated and I need to generate same hash generated in Java in Go.
Java code:
public byte[] sha256Hash(byte[] content) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
return digest.digest(content);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e.getMessage(),e);
}
}
byte[] to ="AA".getBytes();
byte[] shaed = sha256Hash(to);
System.out.println(Arrays.toString(shaed));
Java Output:[88, -69, 17, -100, 53, 81, 58, 69, 29, 36, -36, 32, -17, 14, -112, 49, -20, -123, -77, 91, -4, -111, -99, 38, 62, 126, 93, -104, 104, -112, -100, -75]
Go:
fmt.Println(sha256.Sum256([]byte("AA")))
Go Output:[88 187 17 156 53 81 58 69 29 36 220 32 239 14 144 49 236 133 179 91 252 145 157 38 62 126 93 152 104 144 156 181]