Hello all,
Trying to connect to GameAnalytics REST API from a game I'm building, but HMAC-SHA256 is mandatory and, since I couldn't find a built-in function in GDscript, I'm trying to implement myself. When done, will be a true cross-platform solution for game analytics, no engine recompiling and stuff.
However, tried to no avail and the hash result I get differ from the expected result find in sites like https://www.freeformatter.com/hmac-generator.html
Tried several HMAC-SHA256 generators and they all produce the same output, the bug is in my code.
Data I'm using:
Key: 0123456789012345678901234567890123456789012345678901234567890123
Message: 0123456789012345678901234567890123456789012345678901234567890123ABCD
Using a fixed length key to debug for now.
What I'm doing wrong ??
Code below.
Yes, the code is redundant, ugly, crazy, etc; it's a mix of trying to pinpoint where it went wrong with my recent (1 week) acquired GDscript skills.
func hmac(key, message):
var x = 0
var i = "".toascii()
var o = "".toascii()
var m = message.toascii()
var k = key.toascii()
var s = File.new()
while x < 64:
o.append(k[x] ^ 0x5c)
x += 1
x = 0
while x < 64:
i.append(k[x] ^ 0x36)
x += 1
var temp1 = i + m
s.open("user://s.save", File.WRITE)
s.store_buffer(temp1)
s.close()
var z = s.get_sha256("user://s.save")
var temp2 = z.to_ascii()
var temp3 = o + temp2
s.open("user://s.save", File.WRITE)
s.store_buffer(temp3)
s.close()
z = s.get_sha256("user://s.save")
return z