/// <summary> /// 登录页 /// </summary> /// <returns></returns> public ActionResult Login() { var keys = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS1); Response.Cookies.Append(nameof(keys.PublicKey), keys.PublicKey, new CookieOptions() { SameSite = SameSiteMode.Lax }); HttpContext.Session.Set(nameof(keys.PrivateKey), keys.PrivateKey); string from = Request.Query["from"]; if (!string.IsNullOrEmpty(from)) { from = HttpUtility.UrlDecode(from); Response.Cookies.Append("refer", from, new CookieOptions() { SameSite = SameSiteMode.Lax }); } if (HttpContext.Session.Get <UserInfoDto>(SessionKey.UserInfo) != null) { if (string.IsNullOrEmpty(from)) { return(RedirectToAction("Index", "Home")); } return(LocalRedirect(from)); } if (Request.Cookies.Count > 2) { string name = Request.Cookies["username"]; string pwd = Request.Cookies["password"]?.DesDecrypt(AppConfig.BaiduAK); var userInfo = UserInfoService.Login(name, pwd); if (userInfo != null) { Response.Cookies.Append("username", name, new CookieOptions() { Expires = DateTime.Now.AddYears(1), SameSite = SameSiteMode.Lax }); Response.Cookies.Append("password", Request.Cookies["password"], new CookieOptions() { Expires = DateTime.Now.AddYears(1), SameSite = SameSiteMode.Lax }); HttpContext.Session.Set(SessionKey.UserInfo, userInfo); HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.LoginRecord), "default", userInfo, ClientIP, LoginType.Default); if (string.IsNullOrEmpty(from)) { return(RedirectToAction("Index", "Home")); } return(LocalRedirect(from)); } } return(View()); }
static void Main(string[] args) { RsaKey keys = RsaCrypt.GenerateRsaKeys(); Console.WriteLine(keys.PublicKey); Console.WriteLine(keys.PrivateKey); }
public static void Main(string[] args) { var myClass = new MyClass() { MyProperty1 = 1, Name = "1", Parent = new MyClass() { Name = "mc" } }; var path = myClass.Path(); Console.WriteLine(path); myClass.SetProperty(nameof(MyClass.MyProperty1), 1); Console.ReadKey(); var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048); Console.WriteLine(rsaKey.PrivateKey); Console.WriteLine(rsaKey.PublicKey); var enc = "123456".RSAEncrypt(); Console.WriteLine(enc); Console.Beep(); var dec = enc.RSADecrypt(); Console.WriteLine(dec); Console.ReadKey(); //CreateWebHostBuilder(args).Build().Run(); }
public async Task <IActionResult> Rsa(string str) { var rsaKey = RsaCrypt.GenerateRsaKeys(); var enc = str.RSAEncrypt(); var dec = enc.RSADecrypt(); return(Ok(dec)); }
RedirectManager() { // Initialize RSA crypt Crypt = new RsaCrypt(); Crypt.InitializeEncryption(RsaStore.D, RsaStore.P, RsaStore.Q, RsaStore.DP, RsaStore.DQ, RsaStore.InverseQ); Crypt.InitializeDecryption(RsaStore.Exponent, RsaStore.Modulus); }
public static void Main(string[] args) { var cpa = new ComplexPasswordAttribute(6, 30) { MustNumber = false, MustSymbol = true, MustLetter = false }; var valid = cpa.IsValid("000000a"); Console.WriteLine(cpa.ErrorMessage); Console.ReadKey(); var myClass = new MyClass() { MyProperty1 = 1, Id = "mcc", Pid = "mc", Parent = new MyClass() { Id = "mc", Pid = "ccc", Parent = new MyClass() { Id = "ccc" } } }; var allParent = myClass.AllParent().Append(myClass); var tree = allParent.ToTreeGeneral(c => c.Id, c => c.Pid); Console.WriteLine(tree.ToJsonString(new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented })); var path = myClass.Path(c => c.Id); Console.WriteLine(path); myClass.SetProperty(nameof(MyClass.MyProperty1), 1); Console.ReadKey(); var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048); Console.WriteLine(rsaKey.PrivateKey); Console.WriteLine(rsaKey.PublicKey); var enc = "123456".RSAEncrypt(); Console.WriteLine(enc); Console.Beep(); var dec = enc.RSADecrypt(); Console.WriteLine(dec); Console.ReadKey(); //CreateWebHostBuilder(args).Build().Run(); }
private static void Main(string[] args) { string?s = null; s.IsNotNullAll(); var rsa = RsaCrypt.GetRsaKeyAsync().Result; var eContent = "Test".ToRsaEncrypt(rsa); var dContent = eContent.RsaDecrypt(rsa); }
public ConnectTo() : base(ServerOpcodes.ConnectTo) { Payload = new ConnectPayload(); Payload.PanamaKey = "F41DCB2D728CF3337A4FF338FA89DB01BBBE9C3B65E9DA96268687353E48B94C".ToByteArray(); Payload.Adler32 = 0xA0A66C10; Crypt = new RsaCrypt(); Crypt.InitializeEncryption(RsaStore.P, RsaStore.Q, RsaStore.DP, RsaStore.DQ, RsaStore.InverseQ); }
public static void Main(string[] args) { var rsaKey = RsaCrypt.GenerateRsaKeys(); var enc = "123456".RSAEncrypt(); var dec = enc.RSADecrypt(); Console.WriteLine(dec); Console.ReadKey(); //CreateWebHostBuilder(args).Build().Run(); }
RedirectManager() { WorldNodes = new ConcurrentDictionary <int, WorldNode>(); // Initialize RSA crypt Crypt = new RsaCrypt(); Crypt.InitializeEncryption(RsaStore.D, RsaStore.P, RsaStore.Q, RsaStore.DP, RsaStore.DQ, RsaStore.InverseQ); Crypt.InitializeDecryption(RsaStore.Exponent, RsaStore.Modulus); LoadAvailableWorldNodes(); }
public static void Main(string[] args) { Enumerable.Range(1, 2).Select(i => new { 序号 = i, 图片 = new Dictionary <string, FileStream>() { ["https://ldqk.org/1383"] = File.OpenRead(@"D:\images\emotion\16.jpg") } }).ToDataTable("aa").ToExcel().SaveFile(@"Y:\2.xlsx"); var myClass = new MyClass() { MyProperty1 = 1, Id = "mcc", Pid = "mc", Parent = new MyClass() { Id = "mc", Pid = "ccc", Parent = new MyClass() { Id = "ccc" } } }; var allParent = myClass.AllParent().Append(myClass); var tree = allParent.ToTreeGeneral(c => c.Id, c => c.Pid); Console.WriteLine(tree.ToJsonString(new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented })); var path = myClass.Path(c => c.Id); Console.WriteLine(path); myClass.SetProperty(nameof(MyClass.MyProperty1), 1); Console.ReadKey(); var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048); Console.WriteLine(rsaKey.PrivateKey); Console.WriteLine(rsaKey.PublicKey); var enc = "123456".RSAEncrypt(); Console.WriteLine(enc); Console.Beep(); var dec = enc.RSADecrypt(); Console.WriteLine(dec); Console.ReadKey(); //CreateWebHostBuilder(args).Build().Run(); }
public void RsaCryptWordTestWithNoException() { var rsaKey = RsaCrypt.GenerateRsaKeys(); string result = new RsaCryptTestEntity() { SdTime = DateTime.Parse("2020-08-14"), Name = "asdf" } .ToJsonExt() .RSAEncrypt() .RSADecrypt(); Assert.Equal(result, "123"); }
public static void Main(string[] args) { var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048); Console.WriteLine(rsaKey.PrivateKey); Console.WriteLine(rsaKey.PublicKey); var enc = "123456".RSAEncrypt(); Console.WriteLine(enc); Console.Beep(); var dec = enc.RSADecrypt(); Console.WriteLine(dec); Console.ReadKey(); //CreateWebHostBuilder(args).Build().Run(); }
public static void Main(string[] args) { var myClass = new MyClass() { MyProperty1 = 1, Id = "mcc", Pid = "mc", Parent = new MyClass() { Id = "mc", Pid = "ccc", Parent = new MyClass() { Id = "ccc" } } }; var allParent = myClass.AllParent().Append(myClass); var tree = allParent.ToTreeGeneral(c => c.Id, c => c.Pid); tree.Flatten(t => t.Children).Select(t => t.Value).ToDataTable().ToExcel().SaveFile(@"Y:\1.xlsx"); Console.WriteLine(tree.ToJsonString(new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented })); var path = myClass.Path(c => c.Id); Console.WriteLine(path); myClass.SetProperty(nameof(MyClass.MyProperty1), 1); Console.ReadKey(); var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048); Console.WriteLine(rsaKey.PrivateKey); Console.WriteLine(rsaKey.PublicKey); var enc = "123456".RSAEncrypt(); Console.WriteLine(enc); Console.Beep(); var dec = enc.RSADecrypt(); Console.WriteLine(dec); Console.ReadKey(); //CreateWebHostBuilder(args).Build().Run(); }
static void Main(string[] args) { var rsaKey = RsaCrypt.GenerateRsaKeys(512); Console.WriteLine(rsaKey.PrivateKey); var enc = new MyClass() { SdTime = DateTime.Now, MyProperty = "asdf" }.ToJsonString().RSAEncrypt(); Console.WriteLine(enc); Console.WriteLine(HiPerfTimer.Execute(() => { var dec = enc.RSADecrypt(); Console.WriteLine(dec); }) * 1000); }
public ConnectTo() { byte[] expr_1B = new byte[130]; ConnectTo.smethod_0(expr_1B, fieldof(< PrivateImplementationDetails >.struct10_0).FieldHandle); this.PiDigits = expr_1B; base..ctor(); while (true) { IL_11C: uint arg_F8_0 = 3993814791u; while (true) { uint num; switch ((num = (arg_F8_0 ^ 2867687330u)) % 6u) { case 0u: goto IL_11C; case 2u: this.Crypt = new RsaCrypt(); arg_F8_0 = (num * 2459550961u ^ 137469758u); continue; case 3u: this.Payload.PanamaKey = Module.smethod_33 <string>(3050187087u).ToByteArray(); this.Payload.Adler32 = 2695261200u; arg_F8_0 = (num * 3197803142u ^ 1130187682u); continue; case 4u: this.Crypt.InitializeEncryption <byte[]>(RsaStore.D, RsaStore.P, RsaStore.Q, RsaStore.DP, RsaStore.DQ, RsaStore.InverseQ, false); this.Crypt.InitializeDecryption <byte[]>(RsaStore.Exponent, RsaStore.Modulus, false); arg_F8_0 = (num * 2948528008u ^ 2475682229u); continue; case 5u: this.Payload = new ConnectTo.ConnectPayload(); arg_F8_0 = (num * 4055527431u ^ 2615824410u); continue; } return; } } }
public static void Main(string[] args) { var list = new List <string>(); list.AddRangeIfNotContains("1", "11"); // 将被添加元素中的长度大于1的元素添加到list var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048); Console.WriteLine(rsaKey.PrivateKey); Console.WriteLine(rsaKey.PublicKey); var enc = "123456".RSAEncrypt(); Console.WriteLine(enc); Console.Beep(); var dec = enc.RSADecrypt(); Console.WriteLine(dec); Console.ReadKey(); //CreateWebHostBuilder(args).Build().Run(); }
public static void Main(string[] args) { var fs = File.OpenRead(@"E:\下载\BlazorSamples.7z"); var bytes = fs.ToArrayAsync().Result; Console.WriteLine(bytes.Length); Console.ReadKey(); var myClass = new MyClass() { MyProperty1 = 1, Name = "1", Parent = new MyClass() { Name = "mc" } }; var path = myClass.Path(); Console.WriteLine(path); myClass.SetProperty(nameof(MyClass.MyProperty1), 1); Console.ReadKey(); var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048); Console.WriteLine(rsaKey.PrivateKey); Console.WriteLine(rsaKey.PublicKey); var enc = "123456".RSAEncrypt(); Console.WriteLine(enc); Console.Beep(); var dec = enc.RSADecrypt(); Console.WriteLine(dec); Console.ReadKey(); //CreateWebHostBuilder(args).Build().Run(); }
public static void Main(string[] args) { bool showHelp = false; string key = null, inputPath = null, outputPath = null, publicPath = null, privatePath = null, command; OptionSet opt = new OptionSet() { {"k|key=", "key file", v => key = v}, {"i|in=", "input file", v => inputPath = v}, {"o|out=", "output file", v => outputPath = v}, {"pub=", "publi key output file", v => publicPath = v}, {"priv=", "private key output file", v => privatePath = v}, {"h|help", "show this message and exit", v => showHelp = v != null}, }; List<string> commands; try { commands = opt.Parse(args); } catch (OptionException e) { PrintError(e.Message); return; } if (showHelp) { Usage(opt); return; } if (0 == commands.Count) { PrintError("No command error"); return; } command = commands[0]; if ("encrypt" != command && "decrypt" != command && "keygen" != command) { PrintError("Invalid command."); return; } if (null == key) { PrintError("No key error"); return; } if (null == inputPath && "keygen" != command) { PrintError("Input file is not specified"); return; } if (null == outputPath && "keygen" != command) { PrintError("Output file is not specified"); return; } FileStream inputFile = null, outputFile = null; if ("encrypt" == command || "decrypt" == command) { try { inputFile = File.Open(inputPath, FileMode.Open, FileAccess.Read, FileShare.None); outputFile = File.Open(outputPath, FileMode.Create, FileAccess.Write, FileShare.None); } catch (Exception e) { PrintError(e.Message); return; } } BigInteger a, b; try { byte[] keyContent = File.ReadAllBytes(key); string[] keys = Encoding.UTF8.GetString(Convert.FromBase64String(Encoding.UTF8.GetString(keyContent))).Split(new Char [] {','}); a = BigInteger.Parse(keys[0]); b = BigInteger.Parse(keys[1]); } catch (Exception e) { PrintError(e.Message); return; } FileStream pubFile = null, privFile = null; if ("keygen" == command) { try { pubFile = File.Open(publicPath, FileMode.Create, FileAccess.Write, FileShare.None); privFile = File.Open(privatePath, FileMode.Create, FileAccess.Write, FileShare.None); } catch (Exception e) { PrintError(e.Message); return; } } RsaCrypt crypt = new RsaCrypt(); switch (command) { case "keygen": crypt.publicFile = pubFile; crypt.privateFile = privFile; crypt.Keygen(a, b); break; case "encrypt": crypt.inputFile = inputFile; crypt.outputFile = outputFile; crypt.Encrypt(a, b); break; case "decrypt": crypt.inputFile = inputFile; crypt.outputFile = outputFile; crypt.Decrypt(a, b); break; } Console.WriteLine("done"); if (null != inputFile) { inputFile.Close(); } if (null != outputFile) { outputFile.Close(); } if (null != pubFile) { pubFile.Close(); } if (null != privFile) { privFile.Close(); } }
public static void HandleConnectTo(WorldClass session, ushort port = 3724, byte conn = 0, WorldClass2 session2 = null) { PacketWriter packetWriter = new PacketWriter(ServerMessage.ConnectTo, true); while (true) { IL_65: uint arg_48_0 = 1189851645u; while (true) { uint num; switch ((num = (arg_48_0 ^ 117810876u)) % 4u) { case 0u: goto IL_65; case 1u: packetWriter.WriteUInt64(12330219965770517405uL); arg_48_0 = (num * 886289363u ^ 1599573856u); continue; case 3u: packetWriter.WriteUInt32(14u); arg_48_0 = (num * 798883457u ^ 2791294625u); continue; } goto Block_1; } } Block_1: RsaCrypt rsaCrypt = new RsaCrypt(); try { rsaCrypt.InitializeEncryption <byte[]>(RsaStore.D, RsaStore.P, RsaStore.Q, RsaStore.DP, RsaStore.DQ, RsaStore.InverseQ, false); while (true) { IL_53C: uint arg_4A2_0 = 1950399364u; while (true) { uint num; switch ((num = (arg_4A2_0 ^ 117810876u)) % 35u) { case 0u: { byte[] array; int num2; array[num2] = (byte)AuthenticationHandler.payloadOrder[num2]; arg_4A2_0 = 778837338u; continue; } case 1u: { byte[] array2; array2[10] = 0; array2[11] = 0; arg_4A2_0 = (num * 3426925493u ^ 1622493560u); continue; } case 2u: { byte[] array2; array2[18] = 0; arg_4A2_0 = (num * 3672511218u ^ 2614652434u); continue; } case 3u: { byte[] array2; array2[0] = 67; arg_4A2_0 = (num * 70935332u ^ 306833328u); continue; } case 4u: { byte[] array2; byte[] array3; array2[22] = array3[1]; arg_4A2_0 = (num * 3674763274u ^ 3649142947u); continue; } case 5u: { byte[] array2; array2[13] = 0; array2[14] = 0; arg_4A2_0 = (num * 788135060u ^ 2778562157u); continue; } case 6u: goto IL_53C; case 7u: { byte[] array2; array2[1] = 253; array2[2] = 184; arg_4A2_0 = (num * 4034181865u ^ 116591846u); continue; } case 8u: { byte[] array2; array2[15] = 0; array2[16] = 0; arg_4A2_0 = (num * 1808574983u ^ 3232411455u); continue; } case 9u: { byte[] array2 = new byte[255]; arg_4A2_0 = (num * 3052653591u ^ 3793484446u); continue; } case 10u: arg_4A2_0 = (num * 566048763u ^ 581218626u); continue; case 11u: { byte[] array2; array2[233] = 42; arg_4A2_0 = (num * 3199619518u ^ 4104188893u); continue; } case 12u: { byte[] array2; array2[5] = 127; arg_4A2_0 = (num * 534924131u ^ 1301694869u); continue; } case 13u: { byte[] array2; array2[20] = 0; byte[] array3 = AuthenticationHandler.smethod_10(port); array2[21] = array3[0]; arg_4A2_0 = (num * 1558897694u ^ 577623817u); continue; } case 14u: { byte[] array2; array2[6] = 0; arg_4A2_0 = (num * 1594444616u ^ 3121916550u); continue; } case 15u: { byte[] array2; AuthenticationHandler.smethod_13(new byte[0].GenerateRandomKey(20), 0, array2, 234, 20); arg_4A2_0 = (num * 1673846917u ^ 3902196868u); continue; } case 16u: { byte[] expr_2B6 = new byte[32]; AuthenticationHandler.smethod_8(expr_2B6, fieldof(< PrivateImplementationDetails >.struct8_0).FieldHandle); byte[] array2; AuthenticationHandler.smethod_13(expr_2B6, 0, array2, 93, 32); AuthenticationHandler.smethod_13(new byte[108], 0, array2, 125, 108); arg_4A2_0 = (num * 3680003173u ^ 2041052791u); continue; } case 17u: { byte[] array2; Array arg_297_0 = rsaCrypt.Encrypt <byte[]>(array2, false); byte[] array4 = new byte[256]; AuthenticationHandler.smethod_14(arg_297_0, array4, 256); arg_4A2_0 = (num * 2289352343u ^ 161977499u); continue; } case 18u: { int num2; num2++; arg_4A2_0 = 1213188245u; continue; } case 19u: { rsaCrypt.InitializeDecryption <byte[]>(RsaStore.Exponent, RsaStore.Modulus, false); byte[] array = new byte[AuthenticationHandler.payloadOrder.Length]; arg_4A2_0 = (num * 163108824u ^ 2004099280u); continue; } case 20u: { byte[] array2; array2[7] = 0; arg_4A2_0 = (num * 669897089u ^ 3823184314u); continue; } case 21u: { int num2 = 0; arg_4A2_0 = (num * 1178352322u ^ 2056709069u); continue; } case 22u: { string string_ = Module.smethod_35 <string>(848950031u); arg_4A2_0 = (num * 560797187u ^ 1592203457u); continue; } case 23u: packetWriter.WriteUInt8(conn); arg_4A2_0 = (num * 264353632u ^ 1806577887u); continue; case 24u: { int num2; arg_4A2_0 = ((AuthenticationHandler.payloadOrder[num2] <= 16) ? 423310451u : 557178527u); continue; } case 25u: { byte[] array2; array2[3] = 34; array2[4] = 1; arg_4A2_0 = (num * 4152105185u ^ 2192753377u); continue; } case 26u: { byte[] array; int num2; array[num2] = (byte)(AuthenticationHandler.payloadOrder[num2] - 3); arg_4A2_0 = (num * 3507665298u ^ 2968893570u); continue; } case 27u: { byte[] array2; array2[12] = 0; arg_4A2_0 = (num * 618037152u ^ 1046649983u); continue; } case 28u: { byte[] array2; array2[19] = 0; arg_4A2_0 = (num * 1680293565u ^ 2487070996u); continue; } case 29u: { int num2; arg_4A2_0 = ((num2 >= AuthenticationHandler.payloadOrder.Length) ? 858439922u : 70439534u); continue; } case 30u: { byte[] array4; AuthenticationHandler.smethod_0(packetWriter, array4); arg_4A2_0 = (num * 216092153u ^ 2688375690u); continue; } case 31u: { byte[] array2; array2[8] = 1; array2[9] = 0; arg_4A2_0 = (num * 3445269463u ^ 748842564u); continue; } case 33u: { byte[] array2; array2[17] = 0; arg_4A2_0 = (num * 40612712u ^ 3030126910u); continue; } case 34u: { byte[] array2; string string_; AuthenticationHandler.smethod_13(AuthenticationHandler.smethod_12(AuthenticationHandler.smethod_11(), string_), 0, array2, 23, 71); arg_4A2_0 = (num * 376848159u ^ 536405427u); continue; } } goto Block_7; } } Block_7 :; } finally { if (rsaCrypt != null) { while (true) { IL_57F : uint arg_566_0 = 461746135u; while (true) { uint num; switch ((num = (arg_566_0 ^ 117810876u)) % 3u) { case 0u: goto IL_57F; case 2u: AuthenticationHandler.smethod_15(rsaCrypt); arg_566_0 = (num * 3554924306u ^ 496472224u); continue; } goto Block_10; } } Block_10 :; } } if (session2 == null) { goto IL_5B1; } IL_58A: int arg_594_0 = 202372283; IL_58F: switch ((arg_594_0 ^ 117810876) % 4) { case 0: IL_5B1: session.Send(ref packetWriter); arg_594_0 = 910700601; goto IL_58F; case 2: goto IL_58A; case 3: session2.Send(ref packetWriter); return; } }
public static async Task SendConnectTo(SessionBase session, RsaCrypt crypt, ulong key, string ip, ushort port, byte connection = 0) { var connectTo = new ConnectTo { Key = key, Serial = 0xE, Con = connection }; // Fail if (connectTo.Key == 0) return; var payloadData = new byte[0xFF]; var ipBytes = IPAddress.Parse(ip).GetAddressBytes(); // 0 - 15, Address, IPv6 not supported for now payloadData[0] = ipBytes[0]; payloadData[1] = ipBytes[1]; payloadData[2] = ipBytes[2]; payloadData[3] = ipBytes[3]; // 16 payloadData[16] = 0x01; // 17 - 20, adler32, changes with compression seed. // Let's use a static one for now payloadData[17] = 0x43; payloadData[18] = 0xfd; payloadData[19] = 0xb8; payloadData[20] = 0x22; // 21 payloadData[21] = 0x2A; var portBytes = BitConverter.GetBytes(port); // 22 - 23, Port payloadData[22] = portBytes[0]; payloadData[23] = portBytes[1]; var msg = "Blossom opens above\nSpines rising to the air\nArctium Emu grows stronger\n"; // 24 - 94, Haiku Array.Copy(Encoding.ASCII.GetBytes(msg), 0, payloadData, 24, 71); // 94 - 125, static for now... Array.Copy(new byte[] { 0xD6, 0xAC, 0x21, 0xE6, 0xB2, 0x7B, 0x06, 0x3D, 0xA9, 0x9C, 0x09, 0x4B, 0xC7, 0x30, 0x48, 0x34, 0xD4, 0xF0, 0x55, 0x3B, 0x1B, 0x1D, 0xC9, 0x5B, 0xFD, 0x3C, 0xB9, 0x30, 0x9D, 0xF5, 0x40, 0xC0 }, 0, payloadData, 94, 32); // 126 - 233, 0 for now Array.Copy(new byte[108], 0, payloadData, 126, 108); // 234 - 253, ranodm for now Array.Copy(new byte[0].GenerateRandomKey(20), 0, payloadData, 234, 20); var dataOrder = new byte[payloadData.Length]; for (var i = 0; i < payloadData.Length; i++) dataOrder[i] = payloadData[ConnectTo.PayloadOrder[i]]; var encrypted = crypt.Encrypt(dataOrder); Array.Copy(encrypted, connectTo.Where, 0x100); await session.Send(connectTo); }
private RsaKey GetRsaKey() { RsaKey rsaKey = RsaCrypt.GenerateRsaKeys();// 生成RSA密钥对 return(rsaKey); }
/// <summary> /// 生成rsa秘钥 /// </summary> /// <param name="rsaKeyType">密钥类型</param> /// <param name="length">密钥长度</param> /// <returns></returns> public RsaKey GenerateRsaKeys(RsaKeyType rsaKeyType = RsaKeyType.XML, int length = 1024) { return(RsaCrypt.GenerateRsaKeys(rsaKeyType, length)); }