예제 #1
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);
        }
예제 #2
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);
        }