Esempio n. 1
0
 private static byte[] ComputeHash(byte[] messageBinary, byte[] privateKeyBinary)
 {
     byte[] result;
     using (HMACSHA256Cng hmacsha256Cng = new HMACSHA256Cng(privateKeyBinary))
     {
         byte[] array = hmacsha256Cng.ComputeHash(messageBinary);
         hmacsha256Cng.Clear();
         result = array;
     }
     return(result);
 }
Esempio n. 2
0
        public void HMACSH256CngPropertyTest()
        {
            using (HMACSHA256 bclHmac = new HMACSHA256())
                using (HMACSHA256Cng cngHmac = new HMACSHA256Cng())
                {
                    Assert.AreEqual(typeof(SHA256Cng).AssemblyQualifiedName, cngHmac.HashName);
                    Assert.AreEqual(bclHmac.HashSize, cngHmac.HashSize);
                    Assert.AreEqual(bclHmac.InputBlockSize, cngHmac.InputBlockSize);
                    Assert.AreEqual(bclHmac.OutputBlockSize, cngHmac.OutputBlockSize);

                    Assert.AreEqual(CngProvider2.MicrosoftPrimitiveAlgorithmProvider, cngHmac.Provider);
                }
        }
Esempio n. 3
0
 private SharepointAccessManager.Key GetKey(SecurityIdentifier userSid, Guid mailboxGuid)
 {
     SharepointAccessManager.Key result;
     using (HMACSHA256Cng hmacsha256Cng = new HMACSHA256Cng(this.hmacKey))
     {
         byte[] array = new byte[userSid.BinaryLength + 16];
         userSid.GetBinaryForm(array, 0);
         Buffer.BlockCopy(mailboxGuid.ToByteArray(), 0, array, userSid.BinaryLength, 16);
         byte[] src    = hmacsha256Cng.ComputeHash(array);
         byte[] array2 = new byte[16];
         Buffer.BlockCopy(src, 0, array2, 0, 16);
         result = new SharepointAccessManager.Key(array2);
     }
     return(result);
 }
Esempio n. 4
0
        public void HMACSHA256CngTest()
        {
            using (RNGCng rng = new RNGCng())
            {
                byte[] key = new byte[64];
                rng.GetBytes(key);

                using (HMACSHA256 bclHmac = new HMACSHA256(key))
                    using (HMACSHA256Cng cngHmac = new HMACSHA256Cng(key))
                    {
                        for (int i = 0; i < 10; ++i)
                        {
                            byte[] data = new byte[2048];
                            rng.GetBytes(data);

                            byte[] bcl = bclHmac.ComputeHash(data);
                            byte[] cng = cngHmac.ComputeHash(data);

                            Assert.IsTrue(Util.CompareBytes(bcl, cng));
                        }
                    }
            }
        }