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)); }
public void Clear() { _hash = _hasher.CreateHash(); }
// Appends a given number of bytes to the hash private static void Append(CryptographicHash hash, int bytesRead, byte[] buffer) { if (bytesRead == buffer.Length) { // append the whole buffer hash.Append(buffer); } else { // only a part of the buffer should be appended, so need a smaller buffer var partialBuffer = new byte[bytesRead]; Array.Copy(buffer, partialBuffer, bytesRead); hash.Append(partialBuffer); } }
/// <summary> /// Implements the Dispose pattern /// </summary> /// <param name="disposing">Whether this object is being disposed via a call to Dispose /// or garbage collected.</param> protected virtual void Dispose(bool disposing) { if (disposing && _hash != null) { _hash.Dispose(); _hash = null; } }