示例#1
0
            internal void Hash()
            {
                if (hashed)
                {
                    return;
                }
                MAC macsha1 = mykh.getHMACSHA1();

                if (salt == null)
                {
                    Random random = Session.random;
                    lock (random)
                    {
                        salt = new byte[macsha1.getBlockSize()];
                        random.fill(salt, 0, salt.Length);
                    }
                }
                try
                {
                    lock (macsha1)
                    {
                        macsha1.init(salt);
                        byte[] foo = host.getBytes();
                        macsha1.update(foo, 0, foo.Length);
                        hash = new byte[macsha1.getBlockSize()];
                        macsha1.doFinal(hash, 0);
                    }
                }
                catch //(Exception e)
                {
                }
                host = HASH_MAGIC + Encoding.UTF8.GetString(Util.toBase64(salt, 0, salt.Length)) +
                       HASH_DELIM + Encoding.UTF8.GetString(Util.toBase64(hash, 0, hash.Length));
                hashed = true;
            }
示例#2
0
            internal override bool isMatched(string _host)
            {
                if (!hashed)
                {
                    return(base.isMatched(_host));
                }
                MAC macsha1 = mykh.getHMACSHA1();

                try
                {
                    lock (macsha1)
                    {
                        macsha1.init(salt);
                        byte[] foo = _host.getBytes();
                        macsha1.update(foo, 0, foo.Length);
                        byte[] bar = new byte[macsha1.getBlockSize()];
                        macsha1.doFinal(bar, 0);
                        return(Util.array_equals(hash, bar));
                    }
                }
                catch (Exception e)
                {
                    Console.Out.WriteLine(e);
                }
                return(false);
            }