Ich möchte den folgenden C# -Code in PHP umwandeln.Was ist das PHP-Äquivalent dieses C# -Codiercodes?
Der C# ist:
byte[] operation = UTF8Encoding.UTF8.GetBytes("getfaqs");
byte[] secret = UTF8Encoding.UTF8.GetBytes("Password");
var hmac = newHMACSHA256(secret);
byte[] hash = hmac.ComputeHash(operation);
Was ich habe in diesem gedreht:
$hash = hash_hmac("sha256", utf8_encode("getfaqs"), utf8_encode("Password"));
Dann habe ich:
var apiKey = "ABC-DEF1234";
var authInfo = apiKey + ":" + hash
//base64 encode the authorisation info
var authorisationHeader = Convert.ToBase64String(Encoding.UTF8.GetBytes(authInfo));
Was ich denke, sollte sein:
$authInfo = base64_encode($apiKey . ":" . $hash);
Oder
$authInfo = base64_encode(utf8_encode($apiKey . ":" . $hash));
aber nicht sicher, diese zweite Codierung bemerken verwendet Encoding.UTF8, nicht UTF8Encoding.UTF8.
Wie sollte der PHP-Code aussehen?
'UTF8Encoding.UTF8' und' Encoding.UTF8 'sind gleichwertig. 'UTF8Encoding' erbt von'Encoding' und erhält als Ergebnis die 'UTF8'-Eigenschaft. –