Пример #1
0
        /// <summary>
        /// 二次加密数据方式
        /// </summary>
        /// <param name="secondpwd">二次加密密码</param>
        /// <param name="str">加密字符串</param>
        /// <returns></returns>
        private string SecondPwdEncryptionData(string secondpwd, string str, PassWordBookSaveType type)
        {
            string sencondMd5 = IEncryptAndDecodeServer.GetMd532(secondpwd);

            //使用密码做AES加密
            str = IEncryptAndDecodeServer.AesEncryption(str, secondpwd);
            //拼接字符串
            str = sencondMd5 + str + IEncryptAndDecodeServer.GetMd532(sencondMd5 + str);
            //拼接外部Json结构
            JObject jtoken = new JObject();

            jtoken["SecondAuthentication"] = type.ToString();
            jtoken["Data"] = str;
            return(jtoken.ToString());
        }
Пример #2
0
        /// <summary>
        /// 保存账号密保
        /// </summary>
        /// <param name="filePath"></param>
        public void SaveShield(string filePath, string password)
        {
            string account    = CurPassWordBookModel.Account;
            string accountMd5 = IEncryptAndDecodeServer.GetMd532(account);

            //1、SHA512
            account = IEncryptAndDecodeServer.GetSha512(account);
            //2、数组逆转
            var oldArray = account.ToArray();

            Char[] newArray = new Char[oldArray.Length];
            for (int i = 0; i < oldArray.Length; i++)
            {
                newArray[oldArray.Length - 1] = oldArray[i];
            }
            //3、获取MD5
            account = IEncryptAndDecodeServer.GetMd532(new string(newArray));

            if (CurPassWordBookModel.IsComputer)
            {
                string computerStr = getComputer();
                string computerMd5 = IEncryptAndDecodeServer.GetMd532(computerStr);
                //1、机器码SHA
                computerStr = IEncryptAndDecodeServer.GetSha1(computerStr);
                //2、数组逆转
                oldArray = computerStr.ToArray();
                newArray = new Char[oldArray.Length];
                for (int i = 0; i < oldArray.Length; i++)
                {
                    newArray[oldArray.Length - 1] = oldArray[i];
                }
                //3、获取MD5
                computerStr = IEncryptAndDecodeServer.GetMd532(new string(newArray));
                //4、加密AES密码
                password = IEncryptAndDecodeServer.AesEncryption(password, computerStr);
                //5、验证数据拼接
                password = computerMd5 + password + IEncryptAndDecodeServer.GetMd532((computerMd5 + password));
            }
            else
            {
                string zero = "00000000000000000000000000000000";
                password = zero + password + IEncryptAndDecodeServer.GetMd532((zero + password));
            }
            account = IEncryptAndDecodeServer.AesEncryption(password, account);
            IFileServer.SaveFile(account, accountMd5, filePath);
        }
Пример #3
0
        /// <summary>
        /// 保存单个密码本
        /// </summary>
        /// <param name="passwordbook">数据</param>
        /// <param name="type">密保类型</param>
        /// <param name="secondpwd">二次密码</param>
        /// <returns>物理认证加密后的密保文件</returns>
        public string SavePassWordBook(Model.PassWordBookModel passwordbook, PassWordBookSaveType type, string secondpwd)
        {
            if (!CachePassWordSecurity.GetInstance().IsCache)
            {
                throw new ExceptionSecurityTimeout("密码验证超时需要再次做密码验证");
            }
            if (type == PassWordBookSaveType.AuthPassWord && string.IsNullOrEmpty(secondpwd))
            {
                throw new Exception("使用二次密码认证,二次密码不能为空");
            }
            string savePhysicsStr = string.Empty;

            //设置时间标记
            passwordbook.CreateDate = DateTime.Now;

            Newtonsoft.Json.Linq.JToken jtoken = new JObject();
            jtoken["SecondAuthentication"] = type.ToString();
            jtoken["PassWord"]             = passwordbook.PassWord;
            //移除密码显示存储。
            passwordbook.PassWord = string.Empty;
            jtoken["Data"]        = Newtonsoft.Json.JsonConvert.SerializeObject(passwordbook.Data);

            string saveStr = jtoken.ToString();

            //针对不同类型进行不同的加密处置方式
            switch (type)
            {
            case PassWordBookSaveType.Null:
                break;

            case PassWordBookSaveType.AuthEmailCode:
                break;

            case PassWordBookSaveType.AuthPhoneCode:
                break;

            case PassWordBookSaveType.AuthPassWord:
                saveStr = SecondPwdEncryptionData(secondpwd, saveStr, type);
                break;

            case PassWordBookSaveType.PhysicsCode:
                secondpwd = GetRandomPassWord(12);
                saveStr   = SecondPwdEncryptionData(secondpwd, saveStr, type);
                //创建物理的密钥文件
                savePhysicsStr = IEncryptAndDecodeServer.AesEncryption(secondpwd, CachePassWordSecurity.GetInstance().Security);
                break;

            default:
                break;
            }

            //使用密码证书做AES加密
            saveStr = IEncryptAndDecodeServer.AesEncryption(saveStr, CachePassWordSecurity.GetInstance().Security);
            //保存密码本文件
            IFileServer.SaveFile(saveStr, CurPassWordBookModel.PassWordCertificate, passwordbook.FilePath);

            CurPassWordBookModel.PassWordBooks.Add(passwordbook);
            SaveAccount();

            return(savePhysicsStr);
        }