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));
        }
예제 #2
0
 public void Clear()
 {
     _hash = _hasher.CreateHash();
 }
예제 #3
0
 // 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);
     }
 }
예제 #4
0
 /// <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;
     }
 }