/// <summary> /// 解密按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDesDecrypt_Click(object sender, EventArgs e) { string key = this.tboxDesKey.Text.ToString().Trim(); string reqData = this.tboxDesReqData.Text.ToString().Trim(); if (key == "") { MessageBox.Show("密钥不能为空!"); return; } if (key.Length % 8 != 0) { MessageBox.Show("密钥长度有误!"); return; } if (reqData == "") { MessageBox.Show("数据不能为空!"); return; } if (reqData.Length % 8 != 0) { MessageBox.Show("数据长度有误"); return; } string result = DesEncryptUtil.desDecrypt(reqData, key); this.tboxDesResult.Text = result; }
public static void UseNlog(this IApplicationBuilder app) { LogManager.LoadConfiguration("nlog.config").GetCurrentClassLogger(); LogManager.Configuration.Variables["configDir"] = Appsettings.app("AppSettings", "LogFilesDir"); var connectionString = DesEncryptUtil.Decrypt(Appsettings.app("ConnectionStrings", "MySqlConnectionString")); LogManager.Configuration.Variables["connectionString"] = connectionString; System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); //避免日志中的中文输出乱码 }
/// <summary> /// PIN加密-解密按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPinDecrypt_Click(object sender, EventArgs e) { string masterKey = this.tboxPinMasterKey.Text.Trim(); string pinKey = this.tboxPinKey.Text.Trim(); string cardNo = this.tboxPinCardNo.Text.Trim(); string pin = this.tboxPinPassword.Text.Trim(); if (masterKey != "" && masterKey.Length % 8 != 0) { MessageBox.Show("主密钥长度有误!"); return; } if (pinKey == "") { MessageBox.Show("PIN密钥不能为空!"); return; } if (pinKey.Length % 8 != 0) { MessageBox.Show("PIN密钥长度有误!"); return; } if (pin == "") { MessageBox.Show("密码不能为空!"); return; } if (masterKey != "") { pinKey = DesEncryptUtil.desDecrypt(pinKey, masterKey); } //带卡号加密 if (cardNo != "") { //解密 string pinBlock = DesEncryptUtil.desDecrypt(pin, pinKey); byte[] pinBlockClearText = PinUtil.reverse(cardNo, pinBlock); string result = StringUtil.byteToHexString(pinBlockClearText); this.tboxPinResult.Text = result; } //不带卡号加密 else { string result = DesEncryptUtil.desDecrypt(pin, pinKey); this.tboxPinResult.Text = result; } }
/// <summary> /// X9.19 MAC计算按钮点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnMacEncryptX919_Click(object sender, EventArgs e) { string masterKey = this.tboxMacMasterKey.Text.Trim(); string macKey = this.tboxMacMacKey.Text.Trim(); string reqData = this.tboxMacReqData.Text.Trim(); if (masterKey != "" && masterKey.Length % 8 != 0) { MessageBox.Show("主密钥长度有误!"); return; } if (macKey == "") { MessageBox.Show("MAC密钥不能为空!"); return; } if (macKey.Length % 8 != 0 || macKey.Length < 32) { MessageBox.Show("MAC密钥长度有误!"); return; } if (reqData == "") { MessageBox.Show("数据不能为空!"); return; } if (masterKey != "") { macKey = DesEncryptUtil.desDecrypt(macKey, masterKey); } reqData = reqData.Replace(" ", ""); reqData = reqData.Replace("\n", ""); reqData = reqData.Replace("\t", ""); reqData = reqData.Replace("\r", ""); string result = ANSIX919.getMac(reqData, macKey); this.tboxMacResult.Text = result; }
/// <summary> /// 核心代码,获取连接实例 /// 通过双if 夹lock的方式,实现单例模式 /// </summary> /// <returns></returns> private ConnectionMultiplexer GetConnection() { //如果已经连接实例,直接返回 if (_connection != null && _connection.IsConnected) { return(_connection); } //加锁,防止异步编程中,出现单例无效的问题 lock (_redisLock) { //释放redis连接 _connection?.Dispose(); try { var config = new ConfigurationOptions { AbortOnConnectFail = false, AllowAdmin = true, ConnectTimeout = 15000, //改成15s SyncTimeout = 5000, EndPoints = { _connenctionString } // connectionString 为IP:Port 如”192.168.2.110:6379” }; if (!string.IsNullOrEmpty(_connenctionPwd)) { config.Password = DesEncryptUtil.Decrypt(_connenctionPwd); //Redis数据库密码; } _connection = ConnectionMultiplexer.Connect(config); } catch (Exception) { throw new Exception("Redis服务未启用,请开启该服务,并且请注意端口号"); } } return(_connection); }
public static void AddFreeSql(this IServiceCollection services) { IFreeSql fsql = new FreeSqlBuilder() .UseConnectionString(DataType.MySql, DesEncryptUtil.Decrypt(Appsettings.app("ConnectionStrings", "MySqlConnectionString"))) .UseNoneCommandParameter(true) .UseMonitorCommand(cmd => { Trace.WriteLine(cmd.CommandText + ";"); }) .Build(); fsql.Aop.CurdAfter += (s, e) => { Console.WriteLine(e.Sql); LogHelper.Info(e.Sql); if (e.ElapsedMilliseconds > 200) { LogHelper.Warning("Sql执行超时,请注意查看"); } }; services.AddSingleton(fsql); services.AddScoped <UnitOfWorkManager>(); services.AddFreeRepository(filter => filter.Apply <ISoftDeleteEntity>("IsDelete", a => a.IsDelete == false)); }