public static byte[] sha256sum(byte[] key, byte[] message) { IMacAlgorithmProvider provider = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithm.HmacSha256); ICryptographicKey hmacKey = provider.CreateKey(key); byte [] hmac = CryptographicEngine.Sign(hmacKey, message); return(hmac); }
public static bool Verify(byte[] key, byte[] message, byte[] signature) { IMacAlgorithmProvider provider = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithm.HmacSha256); ICryptographicKey hmacKey = provider.CreateKey(key); return(CryptographicEngine.VerifySignature(hmacKey, message, signature)); }
static string Sign(string stringToSign, string deviceSymmetricKey) { IMacAlgorithmProvider algorithm = WinRTCrypto.MacAlgorithmProvider.OpenAlgorithm(MacAlgorithm.HmacSha256); PCLCrypto.CryptographicHash hash = algorithm.CreateHash(Convert.FromBase64String(deviceSymmetricKey)); hash.Append(Encoding.UTF8.GetBytes(stringToSign)); byte[] mac = hash.GetValueAndReset(); return(Convert.ToBase64String(mac)); }