예제 #1
0
        private static byte [] HMACSHA1HashForData(byte [] buf, byte [] modifier, int start, int length)
        {
            ExtendedHMACSHA1 hmac = ExtendedHMACSHA1.GetHMACSHA1();        // Pick up an ExtendedHMACSHA1 off the pool

            HMACBuffer [] hbufs;

            if (modifier != null)
            {
                hbufs           = new HMACBuffer[2];
                hbufs[1].buffer = modifier;
                hbufs[1].start  = 0;
                hbufs[1].length = modifier.Length;
            }
            else
            {
                hbufs = new HMACBuffer[1];
            }

            hbufs[0].buffer = buf;
            hbufs[0].start  = start;
            hbufs[0].length = length;

            byte [] ret = hmac.ComputeHash(hbufs);

            ExtendedHMACSHA1.ReturnHMACSHA1(hmac);

            return(ret);
        }
예제 #2
0
        internal static void ReturnHMACSHA1(ExtendedHMACSHA1 hmac)
        {
            if (sha1s == null)
            {
                return;
            }

            lock (sha1s) {
                if (sha1s.Count > 100)
                {
                    return;
                }
                else
                {
                    sha1s.Push(hmac);
                }
            }
        }
예제 #3
0
        private static void ConfigureEncryptionObject(MachineKeyConfig config)
        {
            s_validationKey = config.ValidationKey;
            byte [] dKey = config.DecryptionKey;
            ExtendedHMACSHA1.SetValidationKey(s_validationKey);
            config.DestroyKeys();

            if (config.AutogenKey)
            {
                try {
                    s_oDes     = new TripleDESCryptoServiceProvider();
                    s_oDes.Key = dKey;
                }
                catch (Exception) {
                    if (config.ValidationMode == MachineKeyValidationMode.TripleDES)
                    {
                        throw;
                    }
                    s_oDes = new DESCryptoServiceProvider();
                    byte [] bArray = new byte[8];
                    Buffer.BlockCopy(dKey, 0, bArray, 0, 8);
                    s_oDes.Key = bArray;
                }
            }
            else
            {
                s_oDes = (dKey.Length == 8) ?
                         (SymmetricAlgorithm) new DESCryptoServiceProvider() :
                         (SymmetricAlgorithm) new TripleDESCryptoServiceProvider();
                s_oDes.Key = dKey;
            }
            s_oDes.IV         = new byte[8];
            s_oEncryptorStack = new Stack();
            s_oDecryptorStack = new Stack();
            DestroyByteArray(dKey);
        }