में कनवर्ट करें मेरे पास सी # में निम्न फ़ंक्शन है, एक हैशिंग फ़ंक्शन जिसे मुझे PHP में रूपांतरित करने की आवश्यकता है। मैं PHP में कुछ बातें की कोशिश की है, लेकिन मैं एक ही परिणाम नहीं मिलता है (मैं नेट के साथ अच्छा नहीं कर रहा हूँ)सी # हैशिंग फ़ंक्शन को PHP
private static string GetSignature(string args, string privatekey)
{
var encoding = new System.Text.ASCIIEncoding();
byte[] key = encoding.GetBytes(privatekey);
var myhmacsha256 = new HMACSHA256(key);
byte[] hashValue = myhmacsha256.ComputeHash(encoding.GetBytes(args));
string hmac64 = Convert.ToBase64String(hashValue);
myhmacsha256.Clear();
return hmac64;
}
एक (गलत) PHP में प्रयास यह है:
function encode($data,$key)
{
return base64_encode(hash_hmac('sha256', $data, $key));
}
उत्तर
क्या DampeS8N से नीचे सुझाव दिया गया था की एक मामूली बदलाव मेरे लिए काम किया।
function encode($data,$key)
{
iconv_set_encoding("input_encoding", "ASCII");
iconv_set_encoding("internal_encoding", "ASCII");
iconv_set_encoding("output_encoding", "ASCII");
return base64_encode(hash_hmac('sha256', $data, $key, true));
}
कृपया यह भी नहीं hash_hmac के चौथे पैरामीटर - अब बाइनरी डेटा
यदि आपको सही दिशा में इंगित किया गया है तो आपको DampeS8Ns उत्तर स्वीकार करना चाहिए। – jgauffin