示例#1
0
            internal override bool IsMatched(string _host)
            {
                if (!this.hashed)
                {
                    return(base.IsMatched(_host));
                }
                MAC macsha1 = this._enclosing.GetHMACSHA1();

                try
                {
                    lock (macsha1)
                    {
                        macsha1.Init(this.salt);
                        byte[] foo = Util.Str2byte(_host);
                        macsha1.Update(foo, 0, foo.Length);
                        byte[] bar = new byte[macsha1.GetBlockSize()];
                        macsha1.DoFinal(bar, 0);
                        return(Util.Array_equals(this.hash, bar));
                    }
                }
                catch (Exception e)
                {
                    System.Console.Out.WriteLine(e);
                }
                return(false);
            }
示例#2
0
            internal virtual void Hash()
            {
                if (this.hashed)
                {
                    return;
                }
                MAC macsha1 = this._enclosing.GetHMACSHA1();

                if (this.salt == null)
                {
                    Random random = Session.random;
                    lock (random)
                    {
                        this.salt = new byte[macsha1.GetBlockSize()];
                        random.Fill(this.salt, 0, this.salt.Length);
                    }
                }
                try
                {
                    lock (macsha1)
                    {
                        macsha1.Init(this.salt);
                        byte[] foo = Util.Str2byte(this.host);
                        macsha1.Update(foo, 0, foo.Length);
                        this.hash = new byte[macsha1.GetBlockSize()];
                        macsha1.DoFinal(this.hash, 0);
                    }
                }
                catch (Exception)
                {
                }
                this.host = KnownHosts.HashedHostKey.HASH_MAGIC + Util.Byte2str(Util.ToBase64(this
                                                                                              .salt, 0, this.salt.Length)) + KnownHosts.HashedHostKey.HASH_DELIM + Util.Byte2str
                                (Util.ToBase64(this.hash, 0, this.hash.Length));
                this.hashed = true;
            }