MySQL beginner |
|
Hoi mensen,,
Iemand die mij kan vertellen wat er hier fout gaat??
Het is de bedoeling dat er zo'n signature uitkomt:
Citaat: [sig] => YjtLTh8A_wSl4Spim2gssM5QAZ8AtaZxIZmGu4je5Tk )
Echter komt er dit uit:
Citaat: [sig] => OTRFOTg4NzRGMTJBNzE0MTVDMTcyRDNENDJGM0Q1RkU1OUE2RUI1NzczMDIxMzNFODA1RjM1NzRDMEM4M0I0MQ== )
De code die word gebruikt in PHP (Bovenste output)
global $BF3APIKey;
// Convert data to JSON
$urlbase64=array('+'=>'-','/'=>'_','='=>'');
$data=strtr(base64_encode(json_encode($data)),$urlbase64);
$postdata=array();
$postdata['data']=$data;
$postdata['sig']=strtr(base64_encode(hash_hmac('sha256',$data,$BF3APIKey,true)),$urlbase64);
// Convert data to JSON $urlbase64=array('+'=>'-','/'=>'_','='=>''); $postdata['data']=$data; $postdata['sig']=strtr(base64_encode(hash_hmac ('sha256',$data,$BF3APIKey,true)),$urlbase64);
De code die word gebruikt in C# (Onderste output)
public void Information()
{
DateTime now = DateTime.Now;
TimeSpan t = (now - new DateTime(1970, 1, 1).ToLocalTime());
int timestamp = (int)t.TotalSeconds;
string data;
jsonData JD = new jsonData();
JD.clientident = "";
JD.ident = AppIdentMaster;
JD.time = timestamp.ToString();
JD.name = "";
data = JsonConvert.SerializeObject(JD);
string _data = base64Encode(data);
string _sig = Sig(_data, seckey);
}
public static string Sig(string _data, string _key)
{
string message = _data;
string key = _key;
var hmacsha256 = new HMACSHA256(Encoding.UTF8.GetBytes(key));
hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(message));
string s = "";
foreach (byte test in hmacsha256.Hash)
{
s += test.ToString("X2");
}
s = s.Replace("+", "-").Replace("/", "_").Replace("=", string.Empty);
return base64Encode(s);
}
public static string base64Encode(string data)
{
try
{
byte[] encData_byte = new byte[data.Length];
encData_byte = System.Text.Encoding.UTF8.GetBytes(data);
string encodedData = Convert.ToBase64String(encData_byte);
return encodedData;
}
catch (Exception e)
{
return "error";
}
}
public void Information() { DateTime now = DateTime.Now; TimeSpan t = (now - new DateTime (1970, 1, 1). ToLocalTime()); int timestamp = (int)t.TotalSeconds; string data; jsonData JD = new jsonData (); JD.clientident = ""; JD.ident = AppIdentMaster; JD.time = timestamp.ToString(); JD.name = ""; data = JsonConvert.SerializeObject(JD); string _data = base64Encode(data); string _sig = Sig(_data, seckey); } public static string Sig(string _data, string _key) { string message = _data; string key = _key; var hmacsha256 = new HMACSHA256 (Encoding. UTF8. GetBytes(key )); hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(message)); string s = ""; foreach (byte test in hmacsha256.Hash) { s += test.ToString("X2"); } s = s.Replace("+", "-").Replace("/", "_").Replace("=", string.Empty); return base64Encode(s); } public static string base64Encode(string data) { try { byte[] encData_byte = new byte[data. Length]; encData_byte = System.Text.Encoding.UTF8.GetBytes(data); string encodedData = Convert.ToBase64String(encData_byte); return encodedData; } catch (Exception e) { return "error"; } }
|