示例#1
0
文件: Mac.cs 项目: LunarLanding/ngit
		public static Mac GetInstance (string name)
		{
			Mac m = new Mac ();
			switch (name.ToUpper ()) {
			case "HMACMD5": m.mac = new HMACMD5 (); break;
			case "HMACSHA1": m.mac = new HMACSHA1 (); break;
			}
			if (m.mac == null)
				throw new NotSupportedException ();
			return m;
		}
示例#2
0
		/// <exception cref="System.Exception"></exception>
		public virtual void Init(byte[] key)
		{
			if (key.Length > 20)
			{
				byte[] tmp = new byte[20];
				System.Array.Copy(key, 0, tmp, 0, 20);
				key = tmp;
			}
			SecretKeySpec skey = new SecretKeySpec(key, "HmacSHA1");
			mac = Mac.GetInstance("HmacSHA1");
			mac.Init(skey);
		}
示例#3
0
		/// <exception cref="System.Exception"></exception>
		public virtual void Init(byte[] key)
		{
			if (key.Length > BSIZE)
			{
				byte[] tmp = new byte[BSIZE];
				System.Array.Copy(key, 0, tmp, 0, BSIZE);
				key = tmp;
			}
			SecretKeySpec skey = new SecretKeySpec(key, "HmacMD5");
			mac = Mac.GetInstance("HmacMD5");
			mac.Init(skey);
		}
示例#4
0
文件: Mac.cs 项目: TetradogOther/NSch
        public static Mac GetInstance(string name)
        {
            Mac m = new Mac();

            switch (name.ToUpper())
            {
            case "HMACMD5": m.mac = new HMACMD5(); break;

            case "HMACSHA1": m.mac = new HMACSHA1(); break;
            }
            if (m.mac == null)
            {
                throw new NotSupportedException();
            }
            return(m);
        }