0

我正在使用 HMAC 哈希来保护数据。我在客户端散列数据,在服务器上重建散列,然后进行比较。服务器上的散列(web api)使用特定的盐来加密数据。我现在需要为我的 Windows 8 应用程序使用相同的盐(使用 JavaScript API)。我有执行散列的代码,但是如何提供盐来生成散列,以便我可以在 JavaScript 客户端和服务器上重新创建相同的散列?

这不是服务器问题,而是特定于客户端 JavaScript windows 8 应用程序。这是我用于散列的代码。但是,我在 API 中找不到任何可以让我更改盐的东西......

var provider = Windows.Security.Cryptography.Core.HashAlgorithmProvider.openAlgorithm(
    Windows.Security.Cryptography.Core.HashAlgorithmNames.sha1);
var hash = provider.createHash();
var binary = Windows.Security.Cryptography.CryptographicBuffer.convertStringToBinary(myData, 
         Windows.Security.Cryptography.BinaryStringEncoding.utf8);
hash.append(binary);

var outputHashBinary = hash.getValueAndReset();
var base64Ticket = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(outputHashBinary);
4

1 回答 1

1

您应该使用 MacAlgorithmProvider 而不是 HashAlgorithmProvider。

这是关于 MacAlgorithmProvider 的 MSDN 文章,其中包含 JavaScript 语言示例 http://msdn.microsoft.com/en-us/library/windows/apps/windows.security.cryptography.core.macalgorithmprovider.aspx?cs-save-lang= 1&cs-lang=javascript#code-snippet-1

该示例尝试根据需要创建 HMAC

于 2013-01-26T14:34:12.420 回答