hello forum
one of my applications needs to query APIs that require a signature in HMAC SHA256
I saw the SIGNATURE library but I don't know how to use it and I'm not sure it's the right way
Hi there, I am trying to access the blinktrade bitcoin platform API. I am trying to do the following curl request within B4J, but I am having a hard time. I keep getting invalid APIKey, but I think the problem is with the formating of the code. Here is instructions on the site...
I tried to implement the solution but I'm not sure it works, let me explain
using PHP I have
$hmac = hash_hmac('sha256', $message, $secretKey);
which returns a value
using the suggested code I get another value, I don't think PHP is wrong
the value depends on the text and the key I don't think it should always be different
php always returns the same value if it starts from the same data
Dim results As String = HMACSHA256("The quick brown fox jumped over the lazy dog.", "secret")
Log(results)
B4X:
Public Sub HMACSHA256 (str As String, key As String) As String
Dim data() As Byte
Dim MC As Mac
Dim KG As KeyGenerator
Dim BC As ByteConverter
KG.Initialize("HMACSHA256")
KG.KeyFromBytes(key.GetBytes("UTF8"))
MC.Initialise("HMACSHA256", KG.Key)
MC.Update(str.GetBytes("UTF8"))
data = MC.Sign
Return BC.HexFromBytes(data).ToLowerCase
End Sub
Dim results As String = HMACSHA256("La veloce volpe marrone saltò sopra il cane pigro.", "segreto")
Registro(risultati)
B4X:
Sub pubblico HMACSHA256 (str come stringa, chiave come stringa) come stringa
Dim data() come byte
Dim MC come Mac
Dim KG come generatore di chiavi
Dim BC come ByteConverter
KG.Inizializza("HMACSHA256")
KG.KeyFromBytes(chiave.GetBytes("UTF8"))
MC.Inizializza("HMACSHA256", KG.Chiave)
MC.Aggiornamento(str.GetBytes("UTF8"))
dati = MC.Segno
Restituisce BC.HexFromBytes(dati).ToLowerCase
Fine Sotto
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.