/// <summary> /// 用户登录 /// </summary> /// <returns></returns> public bool CaSignIn(string home, string code, string name, string pass) { string file = Path.Combine(home, CApp.AMON_CFG); if (!File.Exists(file)) { return false; } DFAccess prop = new DFAccess(); prop.Load(file); string data = prop.Get(CApp.AMON_CFG_DATA); if (!CharUtil.IsValidate(data, 344)) { return false; } _Data = Convert.FromBase64String(data); string info = Digest(name, pass); if (info != prop.Get(CApp.AMON_CFG_INFO)) { return false; } string main = prop.Get(CApp.AMON_CFG_MAIN); if (!Decrypt(name, code, pass, main)) { return false; } _Lock = prop.Get(CApp.AMON_CFG_LOCK); this.Name = name; this.Code = code; this.DatHome = home; _Info = info; Look = "Default"; Feel = "Default"; return true; }
/// <summary> /// 设定安全口令 /// </summary> /// <param name="oldPass"></param> /// <param name="secPass"></param> /// <returns></returns> public bool CaAuthSk(string oldPass, string secPass) { DFAccess prop = new DFAccess(); prop.Load(Path.Combine(this.DatHome, CApp.AMON_CFG)); // 已有口令校验 string info = Digest(Name, oldPass); if (info != prop.Get(CApp.AMON_CFG_INFO)) { return false; } // 生成加密密钥及字符空间 byte[] t = new byte[72]; byte[] a = Encoding.UTF8.GetBytes(Code); int i = 0; Array.Copy(a, 0, t, i, a.Length); i += a.Length; Array.Copy(_Salt, 0, t, i, _Salt.Length); i += _Salt.Length; Array.Copy(_Keys, 0, t, i, _Keys.Length); i += _Keys.Length; a = Encoding.UTF8.GetBytes(_Mask); Array.Copy(a, 0, t, i, a.Length); // 口令 byte[] k = GenK(Name, Code, secPass); // 向量 byte[] v = GenV(Name, Code, secPass); #region AES 加密 AesManaged aes = new AesManaged(); using (MemoryStream mStream = new MemoryStream()) { using (CryptoStream cStream = new CryptoStream(mStream, aes.CreateEncryptor(k, v), CryptoStreamMode.Write)) { cStream.Write(t, 0, t.Length); cStream.FlushFinalBlock(); t = mStream.ToArray(); } } aes.Clear(); #endregion prop.Set(CApp.AMON_CFG_SAFE, Convert.ToBase64String(t)); prop.Save(Path.Combine(this.DatHome, CApp.AMON_CFG)); return true; }