Example #1
0
        /// <summary>
        ///     Calculate MAC value.
        /// </summary>
        /// <param name="pduBytes">PDU encoded as byte array</param>
        /// <param name="macAlgorithm">MAC algorithm</param>
        /// <param name="key">HMAC key</param>
        private static DataHash CalcMacValue(byte[] pduBytes, HashAlgorithm macAlgorithm, byte[] key)
        {
            byte[] target = pduBytes.Length < macAlgorithm.Length ? new byte[0] : new byte[pduBytes.Length - macAlgorithm.Length];
            Array.Copy(pduBytes, 0, target, 0, target.Length);

            IHmacHasher hasher = KsiProvider.CreateHmacHasher(macAlgorithm);

            return(hasher.GetHash(key, target));
        }
        public void GetHmacHasherTest()
        {
            IHmacHasher hasher = KsiProvider.CreateHmacHasher(HashAlgorithm.Sha2256);

            Assert.IsNotNull(hasher);
        }
Example #3
0
        /// <summary>
        ///     Calculate MAC for data with given key.
        /// </summary>
        /// <param name="macAlgorithm">MAC algorithm</param>
        /// <param name="key">hmac key</param>
        /// <param name="data">data to calculate MAC from</param>
        /// <returns>mac data hash</returns>
        private static DataHash CalculateMac(HashAlgorithm macAlgorithm, byte[] key, byte[] data)
        {
            IHmacHasher hasher = KsiProvider.CreateHmacHasher(macAlgorithm);

            return(hasher.GetHash(key, data));
        }