我在我的 c# web api 中实现了以下安全编码:
string testStr = "test";
ASCIIEncoding encoding = new ASCIIEncoding(); //using System.Text;
byte[] byteData = encoding.GetBytes(testStr);
MD5 md5 = MD5.Create(); //using System.Security.Cryptography;
string hash = md5.ComputeHash(byteData);
string md5Base64 = Convert.ToBase64String(hash);
我将此字符串绑定md5Base64
在标头中并在 API 请求中进行比较。当我从 C# 代码中访问 API 时,这工作正常。现在我需要在 javascript 中使用它,因此需要与上述代码等效的 js。
我试过以下,但它给出了不同的输出:
var testStr = 'test';
var byteData = testStr.split ('').map(function (c) { return c.charCodeAt (0); });
var hash = MD5(value.join(','));
var md5Base64 = btoa(hash);
这里使用的MD5
函数来自https://stackoverflow.com/a/33486055/7519287
请让我知道这里有什么问题。