public void EncryptTest() { var ptBytes = Encoding.UTF8.GetBytes("This is a plaintext msg"); var result = _security.Encrypt("This is a plaintext msg"); Assert.False(CompareArrays(result, ptBytes)); Console.WriteLine("plainText: " + Encoding.UTF8.GetString(ptBytes)); Console.WriteLine("result: " + Encoding.UTF8.GetString(result)); }
private void simpleButton1_Click(object sender, EventArgs e) { ISecurity md5 = new MD5Security(); ISecurity sec = FT.Commons.Security.SecurityFactory.GetSecurity(); if (this.txtCompany.Text.Trim().Length == 0) { MessageBoxHelper.Show("必须输入授权用户!"); return; } if (this.txtKeyCode.Text.Trim().Length > 0) { if (this.txtKeyCode.Text.Trim() != md5.Encrypt(sec.Encrypt(this.txtMachineCode.Text + this.txtCompany.Text.Trim() + this.txtMachineCode.Text))) { this.txtKeyCode.Focus(); MessageBoxHelper.Show("注册码错误,请重新输入!"); return; } } else { MessageBoxHelper.Show("没有注册码,将使用试用版!"); this.DialogResult = DialogResult.OK; } ProgramRegConfig config = StaticCacheManager.GetConfig <ProgramRegConfig>(); config.RegDate = System.DateTime.Now; loader.SaveConfig(); MessageBoxHelper.Show("保存成功!"); this.DialogResult = DialogResult.OK; }
private void SendMessages() { while (!_shouldClose) { try { string msg = string.Empty; if (!_toSendMsgQueue.IsEmpty) { _toSendMsgQueue.TryDequeue(out msg); // Translate the passed message into ASCII and store it as a Byte array. byte[] data = Encoding.UTF8.GetBytes(msg); string s = Encoding.UTF8.GetString(data); byte[] encrypted = _security.Encrypt(s); s = Encoding.UTF8.GetString(encrypted); s = _security.Decrypt(encrypted); // Send the message to the connected TcpServer. _stream.Write(encrypted, 0, encrypted.Length); } } catch (SocketException e) { Console.WriteLine("SocketException: {0}", e); } } }
protected void SendAllMsgFromQueue(ConcurrentQueue <String> msgQueue, TcpClient tcpClient) { while (!msgQueue.IsEmpty) { try { try { string msg; msgQueue.TryDequeue(out msg); byte[] bytesToSend = Encoding.UTF8.GetBytes(msg); bytesToSend = _security.Encrypt(msg); tcpClient.GetStream().Write(bytesToSend, 0, bytesToSend.Length); } catch (Exception e) { RemoveSocket(tcpClient); } } catch (Exception e) { _socketToUserId.Remove(tcpClient); tcpClient.Close(); } } }
private void SendMsgs(List <string> msgs) { Assert.IsNotNull(_client); Assert.True(_client.Connected); var stream = _client.GetStream(); Assert.True(stream.CanWrite); msgs.ForEach(m => { byte[] bytes = _security.Encrypt(m); stream.Write(bytes, 0, bytes.Length); }); }
public async Task <bool> Handle(AddUserCommand message, CancellationToken cancellationToken) { var roleExists = _userRepository.GetRole(it => it.Id == message.RoleId).Any(); if (!roleExists) { NotifyValidationErrors("Role not found."); return(false); } var hashPassword = _security.Encrypt(message.Password, message.Name); var user = UserFactory.Create(message.Name, message.RoleId, hashPassword); if (!user.IsValid()) { NotifyValidationErrors(user.ValidationResult); } _userRepository.Add(user); return(await Task.FromResult(Commit())); }
public string Authenticate(UserLoginViewModel viewModel, out string error) { error = string.Empty; if (string.IsNullOrWhiteSpace(viewModel.Password) || string.IsNullOrWhiteSpace(viewModel.Name)) { error = "Invalid username or password."; return(null); } var hashPassword = _security.Encrypt(viewModel.Password, viewModel.Name); var user = _userRepository.GetByFilters(user => user.Name.ToLower().Equals(viewModel.Name.ToLower()) && user.Password.ToLower().Equals(hashPassword))?.FirstOrDefault(); if (user == null) { error = "Invalid username or password."; return(null); } return(GenerateToken(user)); }
private static void GetProgramState() { //log4net.LogManager.ResetConfiguration(); log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("log.xml")); ProgramRegConfig config = StaticCacheManager.GetConfig <ProgramRegConfig>(); if (config.KeyCode != null && config.KeyCode.Length > 0) { ISecurity md5 = new MD5Security(); ISecurity sec = FT.Commons.Security.SecurityFactory.GetSecurity(); string[] macs = FT.Commons.Tools.HardwareManager.GetMacArray(); string hardwarecode = string.Empty; for (int i = 0; i < macs.Length; i++) { hardwarecode = md5.Encrypt(macs[i]); if (config.KeyCode == md5.Encrypt(sec.Encrypt(hardwarecode + config.Company + hardwarecode))) { productState = ProgramState.Registed; break; } else if (i == macs.Length - 1) { productState = ProgramState.None; } } } else if (config.RightCode.Length != 0) { productState = ProgramState.Trial; } else { productState = ProgramState.None; } }
static void Main(string[] args) { for (int i = 0; i < 10; i++) { Console.WriteLine("随机产生6位随机码:" + HiPiaoInterface.RandomSmsHelper.GenerateNumberCode(6)); } //HiPiaoInterface.HipiaoTcpHelper.GetTicket(); HiPiaoCache.GetDingXinTicket(); // DingXinResponseObject.Parse(""); Console.ReadLine(); /* * 拼装字符串=MEMBERID26c52c2e-69ae-102e-8c3d-001a4beef7e4fromclientHPMACHINEmobile13911139181normal2planIdb8695e80-065b-11e2-a9dc-001bb97ef1a4seatids4b45e880-f01f-11e0-98ca-001bb97ef1a4,4b711730-f01f-11e0-98ca-001bb97ef1a4 * 密码+卡号加密=f56174a3de82dd6016bd5dff2d770682 * 最终加密md5(r2+r1)=53d1205f9fddc1a3a1fc21f3880a4c84 */ string rr1 = "f56174a3de82dd6016bd5dff2d770682"; string rr2 = "MEMBERID26c52c2e-69ae-102e-8c3d-001a4beef7e4fromclientHPMACHINEmobile13911139181normal2planIdb8695e80-065b-11e2-a9dc-001bb97ef1a4seatids4b45e880-f01f-11e0-98ca-001bb97ef1a4,4b711730-f01f-11e0-98ca-001bb97ef1a4"; // string rr2 = "MEMBERID26c52c2e-69ae-102e-8c3d-001a4beef7e4fromclientHPMACHINEmobile13911139181normal2planidb8695e80-065b-11e2-a9dc-001bb97ef1a4seatids4b45e880-f01f-11e0-98ca-001bb97ef1a4,4b711730-f01f-11e0-98ca-001bb97ef1a4"; //MEMBERID26c52c2e-69ae-102e-8c3d-001a4beef7e4fromclientHPMACHINEmobile13911139181normal2planIdb8695e80-065b-11e2-a9dc-001bb97ef1a4seatids4b45e880-f01f-11e0-98ca-001bb97ef1a4,4b711730-f01f-11e0-98ca-001bb97ef1a4 Console.WriteLine("最终加密结果rr1+rr2为:" + Encrypt(rr2 + rr1)); ISecurity md5 = new MD5Security(); //1b8dc01720fc2b67ad19a3c526c7bca2 Console.WriteLine("最终加密结果为:" + Encrypt("789001")); string menberid = "26c52c2e-69ae-102e-8c3d-001a4beef7e4"; string mobile = "18618237773"; string count = "4"; string planid = "c81f8af0-fb63-11e1-a9dc-001bb97ef1a4@@6"; string seatv = "9be8e070-8acb-11e1-b245-001bb97ef1a4,9be81d20-8acb-11e1-b245-001bb97ef1a4,9be86b40-8acb-11e1-b245-001bb97ef1a4,9be9cad0-8acb-11e1-b245-001bb97ef1a4"; string fromclient = "ANDROID"; string pwd = "789001"; string hipiaocard = "26c52c2e69"; String r1 = "MEMBERID" + menberid + "fromclient" + fromclient + "mobile" + mobile + "normal" + count + "planId" + planid + "seatids" + seatv ; //String r2 = md5.Encrypt(md5.Encrypt(md5.Encrypt(pwd)) +hipiaocard); //String r3 = md5.Encrypt(r1 + r2); Console.WriteLine("r1==" + r1); String r2 = Encrypt(Encrypt(Encrypt(pwd)) + hipiaocard); Console.WriteLine("r2==" + r2); String tmp = r1 + r2; Console.WriteLine("tmp==" + tmp); //MD5Tester tester = new MD5Tester(); // Console.WriteLine("临时加密结果为:" + MD5Tester.Encrypt(tmp,32)); Console.WriteLine("临时加密结果为:" + md5One(tmp)); String r3 = Encrypt(r1 + r2); Console.WriteLine("r3==" + r3); String r4 = "MEMBERID=" + menberid + "&mobile=" + mobile + "&normal=" + count + "&planId=" + planid + "&seatids=" + seatv + "&fromclient" + fromclient; //String query = r4 + "&pass="******"&pass="******"yyyy-MM-dd HH:mm:ss") + "发送购票内容为:" + query); #endif //9457ea0b240e8dfaa85622d371330f89 //MEMBERID=&mobile=18618237773&normal=4&planId=&seatids=&fromclient&pass= // TestConnection2(10000); /* * 3D3514F23F37E13A 丰大驾校 * 4D64496ADCEF53E0 安泰驾校 * 13EE4553EEF0DF7E 市驾培中心 * A59B773F9C3AA159 惠东平安 * C4FA4E8E43E6A92F 惠东怡辉 * 70C1D30CC159B03B 博罗鸿信 * A60793889949C6F6 光大驾校 * 23762878906B059C 亮丽驾校 * AD8045BF9592308E 博罗鸿信 * 3D00BF143CC95448 环球驾校 * F1844D78F2236926 宏达驾校 * 50B4238104DABA1C * E48EF54511ED7D4F 市驾培中心 * 7D66505102C8DB25 隆辉驾校 * 84A883D2309E661D 隆辉驾校 * DCA698218706CA2B 博罗鸿信 * C3F979CF15706C39 金峰驾校 * * * * * ComputerMonitorHelper helper = new ComputerMonitorHelper(); * helper.CheckIsOpenPort(3389); * helper.CheckIsOpenPort("192.168.1.10",3389); * //FT.Commons.WindowsService.BaseWindowService serv = new FT.Commons.WindowsService.ExDiskPluginMonitorService("CDEF", 1000); * //FT.Commons.WindowsService.BaseWindowService serv = new FT.Commons.WindowsService.NetworkMonitorService( 1000); * // FT.Commons.WindowsService.BaseWindowService serv = new FT.Commons.WindowsService.SystemServiceMonitorService(30000); * // FT.Commons.WindowsService.BaseWindowService serv = new FT.Commons.WindowsService.ProcessMonitorService(30000); * * // serv.DoTask(); * //ComputerInitHelper.InitFolderMd5("Windows Xp","Sp3","D:\\自助终端","D:\\自助终端"); * // ComputerInitHelper.InitSystemServices(); * //ComputerInitHelper.InitSystemNetworkCard(); * Console.ReadLine(); */ //ISecurity md5 = new MD5Security(); ISecurity sec = FT.Commons.Security.SecurityFactory.GetSecurity(); //string hardwarecode=FT.Commons.Tools.HardwareManager.GetMachineCode(); // string hardwarecode = "C3F979CF15706C39"; Console.WriteLine("请输入机器码并回车:"); string hardwarecode = Console.ReadLine(); //一友驾校 //E7A7CA598DDDAFA6 // string company = "金峰驾校"; Console.WriteLine("请输入授权用户名称并回车:"); string company = Console.ReadLine(); Console.WriteLine("注册码生成结果为->" + md5.Encrypt(sec.Encrypt(hardwarecode + company + hardwarecode))); /* string path = Environment.CurrentDirectory + "//success.wav"; * SystemDefine.PlaySound(path, 0, SystemDefine.SND_ASYNC | SystemDefine.SND_FILENAME);//播放音乐 * //FT.Commons.Tools.WindowsPrinterHelper.LoopPrinter(); * string printer = @"\\192.168.1.150\Brother DCP-7030 Printer"; * // Console.WriteLine("打印机状态为:"+FT.Commons.Tools.WindowsPrinterHelper.GetPrinterStat(printer).ToString()); * * string cmd = ""+(char)(27)+(char)(33)+(char)(10)+"模"; * byte[] mybyte = System.Text.Encoding.Default.GetBytes(cmd); * for (int i = 0; i < mybyte.Length; i++) * { * Console.WriteLine(i+"="+mybyte[i]); * } * Console.ReadLine(); * */ Console.ReadLine(); }
private void btn_Encrypt_Click(object sender, EventArgs e) { if (!ValidateText(txt_PlainText, "Enter text to encrypt")) { return; } string strPlainText = txt_PlainText.Text.Trim().ToLower().Replace(" ", ""); string strCypher = ""; switch (cmb_Algorithm.SelectedIndex) { case (int)Algorithm.Ceaser: securityModel = new Ceaser(); strCypher = securityModel.Encrypt(strPlainText, new object[1] { nm_Key.Value }); break; case (int)Algorithm.Autokey: if (ValidateKey()) { securityModel = new AutoKey(); strCypher = securityModel.Encrypt(strPlainText, new object[1] { txt_Key.Text }); } break; case (int)Algorithm.Hill: if (!bKeyGenerated) { MessageBox.Show("please set key", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } securityModel = new Hill(); strCypher = securityModel.Encrypt(strPlainText, new object[2] { m_frmMatrix.m_arrMatrix, nm_Key.Value }); break; case (int)Algorithm.Monoalphabetic: if (!bKeyGenerated) { MessageBox.Show("please set key", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } securityModel = new Monoalphabetic(); strCypher = securityModel.Encrypt(strPlainText, new object[] { }); break; case (int)Algorithm.Playfair: if (ValidateKey()) { securityModel = new PlayFair(); strCypher = securityModel.Encrypt(strPlainText, new object[1] { txt_Key.Text }); } break; case (int)Algorithm.RailFence: securityModel = new RailFence(); strCypher = securityModel.Encrypt(strPlainText, new object[1] { nm_Key.Value }); break; case (int)Algorithm.Vigenere: if (ValidateKey()) { securityModel = new Vigenere(); strCypher = securityModel.Encrypt(strPlainText, new object[1] { txt_Key.Text }); } break; case (int)Algorithm.RowTransposition: if (ValidateKey()) { securityModel = new RowTransposition(); strCypher = securityModel.Encrypt(strPlainText, new object[1] { txt_Key.Text }); } break; } txt_CypherText.Text = strCypher; }
/// <summary> /// 判断是否有效注册码 /// </summary> /// <param name="keycode">注册码</param> /// <returns>如果有效返回true</returns> public static bool ValidateKeyCode(string keycode) { string need = md5.Encrypt(SecurityFactory.GetSecurity().Encrypt(HardwareManager.GetMachineCode())); return(need == keycode); }