by
84k 18
0
4
986
0
Top 1% !
Popular
Tagged
Specified
Popularity: 38086th place
This snippet is Public
Architecturex86_64
LanguageC#
Windows VersionWindows7

HmacSha256

Because Windows.Security.Cryptography.Core.MacAlgorithmNames.HmacSha256 doesn't exist in WP8.1 context we need to do another implementation
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1369491/HmacSha256?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using Windows.Security.Cryptography; using Windows.Security.Cryptography.Core; using Windows.Web.Http; using Windows.Web.Http.Headers; // Because Windows.Security.Cryptography.Core.MacAlgorithmNames.HmacSha256 doesn't // exist in WP8.1 context we need to do another implementation public static string HmacSha256(string key, string value) { var keyStrm = CryptographicBuffer.ConvertStringToBinary(key, BinaryStringEncoding.Utf8); var valueStrm = CryptographicBuffer.ConvertStringToBinary(value, BinaryStringEncoding.Utf8); var objMacProv = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha256); var hash = objMacProv.CreateHash(keyStrm); hash.Append(valueStrm); return CryptographicBuffer.EncodeToBase64String(hash.GetValueAndReset()); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus