public NetMessage(byte[] rawData) { int headLength = Marshal.SizeOf(typeof(CommonPackHead)); //分配结构体内存空间 IntPtr structPtr = Marshal.AllocHGlobal(headLength); //将byte数组拷贝到分配好的内存空间 Marshal.Copy(rawData, 0, structPtr, headLength); //将内存空间转换为目标结构体 MessageHead = (CommonPackHead)Marshal.PtrToStructure(structPtr, typeof(CommonPackHead)); //释放内存空间 Marshal.FreeHGlobal(structPtr); /// MsgID = MessageHead.msg_id; UID = (long)MessageHead.uid; byte[] tmpAppend = new byte[MessageHead.option_len]; Array.Copy(rawData, headLength, tmpAppend, 0, MessageHead.option_len); AddAppendData(tmpAppend, MessageHead.option_len); byte[] encryData = new byte[(int)MessageHead.msg_len - headLength - MessageHead.option_len]; Array.Copy(rawData, headLength + MessageHead.option_len, encryData, 0, encryData.Length); encryData = RC4.Decrypt(Encoding.ASCII.GetBytes(encryKey.ToCharArray()), encryData); encryData = Snappy.Sharp.Snappy.Uncompress(encryData); Data = InfibrProtoBuf.Serializer.Deserialize <T>(new MemoryStream(encryData, 0, encryData.Length)); }
public async Task <ClassiiiUser> AuthenticateAsync(T4ooUser t4ooUser, string authCode) { string encryptedPassword = new RC4(authCode).Enc(t4ooUser.password); Dictionary <string, object> t4ooUserDict = new Dictionary <string, object> { { "orgId", t4ooUser.orgId }, { "userId", t4ooUser.userId }, { "password", encryptedPassword } }; var content = await HttpUtils.SendAsync(HttpMethod.Post, baseUrl + "/authenticate", null, t4ooUserDict); var byteArray = await content.ReadAsByteArrayAsync(); var responseString = Encoding.UTF8.GetString(byteArray, 0, byteArray.Length); var definition = new { status = "", data = new { accessKey = "", secretKey = "" } }; var serverResp = JsonConvert.DeserializeAnonymousType(responseString, definition); if (serverResp.status != ResponseStatus.Success) { return(null); } return(new ClassiiiUser { AccessKey = serverResp.data.accessKey, SecretKey = serverResp.data.secretKey }); }
public static PRUdpPacket Decode(byte[] bytes) { var hex = bytes.ToHex(); var str = hex.Substring(4, 2); string sessionid = "", sig = "", seqnum = "", connsig = "", fragid = "", payload = ""; var typenflags = str.FromHexToBits(); var checksum = hex.Substring(hex.Length - 8); int[] data = new int[typenflags.Count]; for (int i = 0; i < typenflags.Count; i++) { if ((bool)typenflags[i]) { data[i] = 1; } else { data[i] = 0; } } var flags = Convert.ToString(data[0]) + Convert.ToString(data[1]) + Convert.ToString(data[2]) + Convert.ToString(data[3]) + Convert.ToString(data[4]); var type = Convert.ToString(data[5]) + Convert.ToString(data[6]) + Convert.ToString(data[7]); var packet = new PRUdpPacket(); packet.Type = (PacketTypes)Convert.ToInt32(type, 2); packet.Flags = PFlags.ParseFlags(flags); if (packet.Type == PacketTypes.SYN || packet.Type == PacketTypes.CONNECT) { sessionid = hex.Substring(6, 2); sig = hex.Substring(8, 8); seqnum = hex.Substring(16, 4); connsig = hex.Substring(20, 8); /*var f = connsig.Substring(0, 2); * var ff = connsig.Substring(2, 2); * var fff = connsig.Substring(4, 2); * var ffff = connsig.Substring(6, 2); * connsig = ffff + fff + ff + f;*/ } else if (packet.Type == PacketTypes.DATA) { sessionid = hex.Substring(6, 2); sig = hex.Substring(8, 8); seqnum = hex.Substring(16, 4); fragid = hex.Substring(20, 2); payload = PythonScript.DecompressPacketPayload(RC4.Decrypt(Encoding.ASCII.GetBytes("CD&ML"), hex.Substring(22, hex.Length - 30).FromHex()).ToHex().Substring(2)).Result; packet.RMCPayload = RMCPayload.Decode(payload); } else { sessionid = hex.Substring(6, 2); seqnum = hex.Substring(8, 4); } packet.SessionId = sessionid; packet.Signature = sig; packet.Checksum = checksum; packet.ConnectionSignature = connsig; packet.Payload = payload; return(packet); }
static void AssertEncrypt(byte[] key, byte[] input, byte[] expected) { using (var rc4 = new RC4()) { var output = new byte[input.Length]; rc4.Key = key; rc4.TransformBlock(input, 0, input.Length, output, 0); for (int i = 0; i < output.Length; i++) { Assert.AreEqual(expected[i], output[i], $"output[{i}]"); } } using (var rc4 = new RC4()) { rc4.Key = key; var output = rc4.TransformFinalBlock(input, 0, input.Length); for (int i = 0; i < output.Length; i++) { Assert.AreEqual(expected[i], output[i], $"output[{i}]"); } } }
public static void Main(string[] args) { Console.OutputEncoding = Encoding.Unicode; byte[] key = { 1, 2, 3, 4, 5 }; var dataText = @"Hello Greg!"; var data = Encoding.Unicode.GetBytes(dataText); var cipher = RC4.Encrypt(key, data); var cipherText = Encoding.Unicode.GetString(cipher.ToArray()); var retrieved = RC4.Decrypt(key, cipher); var retrievedText = Encoding.Unicode.GetString(retrieved.ToArray()); Console.WriteLine($"Data text : {dataText}"); Console.WriteLine($"Cipher text : {cipherText}"); Console.WriteLine($"Cipher bytes : {PrintByteArray(cipher.ToArray())}"); Console.WriteLine($"Retrieved text: {retrievedText}"); Console.WriteLine($"Period of first pseudo-random byte: {RC4.GetKeyInitializationPeriod(key, 1)}"); Console.WriteLine($"Period of second pseudo-random byte: {RC4.GetKeyInitializationPeriod(key, 2)}"); Console.ReadKey(); }
public static void DecryptFile(string infile, string outfile, string key, int rounds = 20, string encoding = "iso-8859-1") { if (!File.Exists(infile)) { throw new ArgumentException("Input file does not exist."); } byte[] buff = new byte[buffsize]; byte[] iv = new byte[10]; int read; using (var input = File.OpenRead(infile)) { if ((read = input.Read(iv, 0, 10)) != 10) { throw new Exception("Invalid input file."); } using (var output = File.OpenWrite(outfile)) { List <byte> keybytes = new List <byte>(); keybytes.AddRange(Encoding.GetEncoding(encoding).GetBytes(key.Substring(0, Math.Min(key.Length, 246)))); keybytes.AddRange(iv); var rc4 = new RC4(keybytes.ToArray(), rounds); while ((read = input.Read(buff, 0, buffsize)) > 0) { output.Write(rc4.CryptBytes(buff, read), 0, read); } } } }
static void Main_99(string[] args) { RestClient client = new RestClient(); //client.BaseHost = "http://192.168.2.136:90/clientapi/account/login"; ////client.AddDefaultParameter(p: new Parameter("umail", "*****@*****.**", ParameterType.QueryString)); ////client.AddDefaultParameter(p: new Parameter("upass", "wancai", ParameterType.QueryString)); //RestRequest req = new RestRequest(resource: "http://192.168.2.136:90/clientapi/account/login?&[email protected]&upass=wancai", method: Method.POST); //var res = client.Post(req); RestRequest req_1 = new RestRequest("http://192.168.2.136:90/clientapi/account/login", Method.POST); req_1.AddParameter("umail", "*****@*****.**"); req_1.AddParameter("upass", "wancai"); var resbones = client.Execute(req_1); var b64str = resbones.Content; //var b64str = res.ContentEncoding; //res //WebClient client = new WebClient(); //var b64str = client.DownloadString("http://192.168.2.136:90/clientapi/account/login?&[email protected]&upass=wancai"); var b64dat = Convert.FromBase64String(b64str); RC4 rc4 = new RC4(rcpass); var dch5 = rc4.Decrypt(b64dat); var dc = System.Web.HttpUtility.HtmlDecode(dch5); Console.WriteLine(dc); Console.ReadKey(); }
public Crypt(int keySize) { RC4 = new RC4 { KeySize = keySize }; RC4.GenerateKey(); }
public static _LSAPR_TRUSTED_DOMAIN_AUTH_BLOB CreateTrustedDomainAuthorizedBlob( _LSAPR_AUTH_INFORMATION[] currentOutgoingAuthInfos, _LSAPR_AUTH_INFORMATION[] previousOutgoingAuthInfos, _LSAPR_AUTH_INFORMATION[] currentIncomingAuthInfos, _LSAPR_AUTH_INFORMATION[] previousIncomingAuthInfos, byte[] sessionKey) { _LSAPR_TRUSTED_DOMAIN_AUTH_BLOB retVal = new _LSAPR_TRUSTED_DOMAIN_AUTH_BLOB(); LsaTrustedDomainAuthBlob blob = new LsaTrustedDomainAuthBlob(); Random random = new Random(); blob.randomData = new byte[BLOB_AUTH_RANDOM_LENGTH]; //leads with 512 bytes of random data random.NextBytes(blob.randomData); blob.CurrentOutgoingAuthInfos = MarshalAuthInfos(currentOutgoingAuthInfos); blob.PreviousOutgoingAuthInfos = MarshalAuthInfos(previousOutgoingAuthInfos); blob.CurrentIncomingAuthInfos = MarshalAuthInfos(currentIncomingAuthInfos); blob.PreviousIncomingAuthInfos = MarshalAuthInfos(previousIncomingAuthInfos); blob.CountOutgoingAuthInfos = (uint)(currentOutgoingAuthInfos == null ? 0 : currentOutgoingAuthInfos.Length); //blob.ByteOffsetCurrentOutgoingAuthInfo is the sum of sizeof CountOutgoingAuthInfos, //sizeof ByteOffsetCurrentOutgoingAuthInfo ,sizeof ByteOffsetCurrentOutgoingAuthInfo; blob.ByteOffsetCurrentOutgoingAuthInfo = (uint)(Marshal.SizeOf(blob.CountOutgoingAuthInfos) + Marshal.SizeOf( blob.ByteOffsetCurrentOutgoingAuthInfo) + Marshal.SizeOf(blob.ByteOffsetPreviousOutgoingAuthInfo)); blob.ByteOffsetPreviousOutgoingAuthInfo = (uint)(blob.ByteOffsetCurrentOutgoingAuthInfo + blob.CurrentOutgoingAuthInfos.Length); blob.CountIncomingAuthInfos = (uint)(currentIncomingAuthInfos == null ? 0 : currentIncomingAuthInfos.Length); //same as blob.ByteOffsetCurrentOutgoingAuthInfo blob.ByteOffsetCurrentIncomingAuthInfo = (uint)(Marshal.SizeOf(blob.CountIncomingAuthInfos) + Marshal.SizeOf( blob.ByteOffsetCurrentIncomingAuthInfo) + Marshal.SizeOf(blob.ByteOffsetPreviousIncomingAuthInfo)); blob.ByteOffsetPreviousIncomingAuthInfo = (uint)(blob.ByteOffsetCurrentIncomingAuthInfo + blob.CurrentIncomingAuthInfos.Length); blob.OutgoingAuthInfoSize = (uint)(blob.ByteOffsetPreviousOutgoingAuthInfo + blob.PreviousOutgoingAuthInfos.Length); blob.IncomingAuthInfoSize = (uint)(blob.ByteOffsetPreviousIncomingAuthInfo + blob.PreviousIncomingAuthInfos.Length); byte[] input = ArrayUtility.ConcatenateArrays( blob.randomData, TypeMarshal.ToBytes(blob.CountOutgoingAuthInfos), TypeMarshal.ToBytes(blob.ByteOffsetCurrentOutgoingAuthInfo), TypeMarshal.ToBytes(blob.ByteOffsetPreviousOutgoingAuthInfo), blob.CurrentOutgoingAuthInfos, blob.PreviousOutgoingAuthInfos, TypeMarshal.ToBytes(blob.CountIncomingAuthInfos), TypeMarshal.ToBytes(blob.ByteOffsetCurrentIncomingAuthInfo), TypeMarshal.ToBytes(blob.ByteOffsetPreviousIncomingAuthInfo), blob.CurrentIncomingAuthInfos, blob.PreviousIncomingAuthInfos, TypeMarshal.ToBytes(blob.OutgoingAuthInfoSize), TypeMarshal.ToBytes(blob.IncomingAuthInfoSize)); using (RC4 rc4 = RC4.Create()) { rc4.Key = sessionKey; retVal.AuthBlob = rc4.CreateEncryptor().TransformFinalBlock(input, 0, input.Length); } retVal.AuthSize = (uint)(retVal.AuthBlob.Length); return(retVal); }
/// <summary> /// LEE EL ARCHIVO PARAMETERS.MIT Y OBTIENE EL VALOR DEL PARAMETRO ENVIADO /// </summary> /// <param name="parametro">Parametro a buscar</param> /// <returns></returns> public static string ObtieneParametrosMIT(string parametro) { string parameter = ""; string text; string file; string ruta; ruta = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); file = System.IO.Path.Combine(ruta + "\\MIT\\Data", "parameters.mit"); if (System.IO.File.Exists(file)) { text = System.IO.File.ReadAllText(file); //DESCIFRA EL CONTENIDO DEL ARCHIVO PARAMETERS.MIT text = RC4.Decrypt(text, Info.RC4Key); //SE OBTIENE EL VALOR DEL XML parameter = GetDataXML(parametro, text); } else { parameter = ""; } return(parameter); }
public void Dispose() { if (disposed) { return; } try { IncomingCipher = null; OutgoingCipher = null; Socket = null; Character = null; Account = null; if (Player.PetID != 0 && Player.Pet != null) { Player.Owner.LeaveWorld(Player.Pet); } Player = null; Random = null; ConnectedBuild = null; } catch { return; } finally { disposed = true; } }
private IEnumerator SendRequest(string query, object variables = null, Action <GraphQLResponse> callback = null) { var request = QueryRequest(query, variables); using (UnityWebRequest www = request) { yield return(www.SendWebRequest()); if (www.isNetworkError) { if (callback != null) { callback(new GraphQLResponse(null, www.error)); } yield break; } string responseString = www.downloadHandler.text; responseString = CloudSaveSettings.Encrypted ? RC4.Decrypt(Convert.FromBase64String(responseString)) : responseString; var result = new GraphQLResponse(responseString); if (callback != null) { callback(result); } } request.Dispose(); }
public void RC4TestDec1() { RC4 algorithm = new RC4(); string cipher = algorithm.Decrypt("ÏíDu", "test"); Assert.IsTrue(cipher.Equals("abcd")); }
public void RC4TestDec2() { RC4 algorithm = new RC4(); string cipher = algorithm.Decrypt("0xcfed4475", "0x74657374"); Assert.IsTrue(cipher.Equals("0x61626364", StringComparison.InvariantCultureIgnoreCase)); }
public static string DesencriptaBines(string fileName) { string ruta; string file; string text; ruta = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); file = System.IO.Path.Combine(ruta + "\\MIT\\Data", fileName); if (ExisteArchivo(fileName)) { text = System.IO.File.ReadAllText(file); text = text.Replace("\r\n", ""); text = RC4.Decrypt(text, Info.RC4Key); if (!text.Equals("")) { return(text); } else { return(""); } } else { return(""); } }
public static string PayPassWord(string pwd) { var rc4 = new RC4(); pwd = HttpUtility.UrlEncode(rc4.Encrypt(pwd, "wine")); return(pwd); }
public void Connect(Reconnect reconnect) { OnDisconnectHasBeenCalled = false; _incomingEncryption = new RC4(IncomingKey); _outgoingEncryption = new RC4(OutgoingKey); try { Log.Info("Connecting no using proxy!"); _socket = new Socket(SocketType.Stream, ProtocolType.Tcp); _socket.Connect(new IPEndPoint(IPAddress.Parse(reconnect.Host), reconnect.Port)); _socket.NoDelay = true; _socket.ReceiveTimeout = 5000; _socket.SendTimeout = 5000; Disconnected = false; Start(); _onConnect?.Invoke(); } catch (Exception e) { Log.Error("Disconnecting due to error : " + e.Message); Disconnect(DisconnectReason.ExceptionOnConnection.SetDetails(e.Message)); } }
public EncryptContext(int keySize) { RC4 = new RC4 { KeySize = keySize }; RC4.GenerateKey(); }
public void TestArgumentExceptions() { using (var rc4 = new RC4()) { var buffer = new byte[16]; Assert.AreEqual(1, rc4.InputBlockSize, "InputBlockSize"); Assert.AreEqual(1, rc4.OutputBlockSize, "OutputBlockSize"); Assert.IsFalse(rc4.CanReuseTransform, "CanReuseTransform"); Assert.IsTrue(rc4.CanTransformMultipleBlocks, "CanTransformMultipleBlocks"); Assert.Throws <InvalidOperationException> (() => { var x = rc4.Key; }); Assert.Throws <ArgumentNullException> (() => { rc4.Key = null; }); Assert.Throws <ArgumentException> (() => { rc4.Key = new byte[0]; }); rc4.GenerateIV(); rc4.GenerateKey(); rc4.CreateDecryptor(); rc4.CreateEncryptor(); // TransformBlock input buffer parameters Assert.Throws <ArgumentNullException> (() => rc4.TransformBlock(null, 0, buffer.Length, buffer, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => rc4.TransformBlock(buffer, -1, buffer.Length, buffer, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => rc4.TransformBlock(buffer, 0, -1, buffer, 0)); // TransformBlock output buffer parameters Assert.Throws <ArgumentNullException> (() => rc4.TransformBlock(buffer, 0, buffer.Length, null, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => rc4.TransformBlock(buffer, 0, buffer.Length, buffer, -1)); // TransformFinalBlock Assert.Throws <ArgumentNullException> (() => rc4.TransformFinalBlock(null, 0, buffer.Length)); Assert.Throws <ArgumentOutOfRangeException> (() => rc4.TransformFinalBlock(buffer, -1, buffer.Length)); Assert.Throws <ArgumentOutOfRangeException> (() => rc4.TransformFinalBlock(buffer, 0, -1)); } }
public void Test() { Random random = new Random(123); int byteSize = 800000; byte[] text = new byte[byteSize]; random.NextBytes(text); for (int i = 0; i < 10; ++i) { byte[] key = new byte[8 * i + 8]; random.NextBytes(key); var encrTrans = RC4.Get(key); var decrTrans = RC4.Get(key); byte[] encr = new byte[byteSize]; encrTrans.TransformBlock(text, 0, byteSize, encr, 0); byte[] decr = new byte[byteSize]; decrTrans.TransformBlock(encr, 0, byteSize, decr, 0); for (int j = 0; j < byteSize; ++j) { Assert.AreEqual(text[j], decr[j], $"{j}"); } } }
public void RC4_TestVector_IETF() { byte[] keyStream = ArrayPool <byte> .Shared.Rent(8192); Array.Clear(keyStream); // ArrayPool buffers are not zeroed // echo -n "Internet Engineering Task Force" | sha256sum using var rc4 = new RC4(Convert.FromHexString("1ada31d5cf688221c109163908ebe51debb46227c6cc8b37641910833222772a")); rc4.Process(keyStream); AssertKeyStreamEqual(keyStream, 0, "dd5bcb0018e922d494759d7c395d02d3"); AssertKeyStreamEqual(keyStream, 16, "c8446f8f77abf737685353eb89a1c9eb"); AssertKeyStreamEqual(keyStream, 240, "af3e30f9c095045938151575c3fb9098"); AssertKeyStreamEqual(keyStream, 256, "f8cb6274db99b80b1d2012a98ed48f0e"); AssertKeyStreamEqual(keyStream, 496, "25c3005a1cb85de076259839ab7198ab"); AssertKeyStreamEqual(keyStream, 512, "9dcbc183e8cb994b727b75be3180769c"); AssertKeyStreamEqual(keyStream, 752, "a1d3078dfa9169503ed9d4491dee4eb2"); AssertKeyStreamEqual(keyStream, 768, "8514a5495858096f596e4bcd66b10665"); AssertKeyStreamEqual(keyStream, 1008, "5f40d59ec1b03b33738efa60b2255d31"); AssertKeyStreamEqual(keyStream, 1024, "3477c7f764a41baceff90bf14f92b7cc"); AssertKeyStreamEqual(keyStream, 1520, "ac4e95368d99b9eb78b8da8f81ffa795"); AssertKeyStreamEqual(keyStream, 1536, "8c3c13f8c2388bb73f38576e65b7c446"); AssertKeyStreamEqual(keyStream, 2032, "13c4b9c1dfb66579eddd8a280b9f7316"); AssertKeyStreamEqual(keyStream, 2048, "ddd27820550126698efaadc64b64f66e"); AssertKeyStreamEqual(keyStream, 3056, "f08f2e66d28ed143f3a237cf9de73559"); AssertKeyStreamEqual(keyStream, 3072, "9ea36c525531b880ba124334f57b0b70"); AssertKeyStreamEqual(keyStream, 4080, "d5a39e3dfcc50280bac4a6b5aa0dca7d"); AssertKeyStreamEqual(keyStream, 4096, "370b1c1fe655916d97fd0d47ca1d72b8"); ArrayPool <byte> .Shared.Return(keyStream); }
private void ParseMinaQueueThread() { try { while (true) { byte[] body = _minaQueue.Dequeue(); if (body != null) { _parser.Do(RC4.Convert(body, 4)); } Thread.Sleep(10); } } catch (SocketException ex) { Shutdown(); Notified?.Invoke(CVResult.ReceiveCallbackFailed, ex); } catch (ObjectDisposedException) { _connected = false; Notified?.Invoke(CVResult.InfocenterNotConnected, this); } catch (Exception ex) { Notified?.Invoke(CVResult.ExceptionHappened, ex); } }
public void RC4TestNewDec() { RC4 algorithm = new RC4(); string cipher = algorithm.Decrypt("ÏîFp", "test"); Assert.IsTrue(cipher.Equals("aaaa")); }
public static byte[] WhatsappEncrypt(byte[] key, byte[] data, bool appendHash) { if (encryptionOutgoing == null) { encryptionOutgoing = new RC4(key, 256); } HMACSHA1 h = new HMACSHA1(key); byte[] buff = new byte[data.Length]; Buffer.BlockCopy(data, 0, buff, 0, data.Length); encryptionOutgoing.Cipher(buff); byte[] hashByte = h.ComputeHash(buff); byte[] response = new byte[4 + buff.Length]; if (appendHash) { Buffer.BlockCopy(buff, 0, response, 0, buff.Length); Buffer.BlockCopy(hashByte, 0, response, buff.Length, 4); } else { Buffer.BlockCopy(hashByte, 0, response, 0, 4); Buffer.BlockCopy(buff, 0, response, 4, buff.Length); } return(response); }
List <User> GetUsers() { List <User> users = new List <User>(); foreach (string str in RC4.R4DecoderText(Key, File.ReadAllBytes(Environment.CurrentDirectory + "\\db.txt")).Split('\n')) { string[] strSplit = str.Split(' '); bool passwordLimit = false; bool lockUser = false; bool tempPassword = false; if (strSplit[2] != "False") { passwordLimit = true; } if (strSplit[3] != "False") { lockUser = true; } if (strSplit[4] != "False") { tempPassword = true; } users.Add(new User(strSplit[0], strSplit[1], passwordLimit, lockUser, tempPassword)); } return(users); }
public ServerConnection(string host) { this.m_Connection = new TcpClient(); this.m_Host = host; this.m_SendCrypto = new RC4(new byte[] { 0x7a, 0x43, 0x56, 0x32, 0x74, 0x73, 0x59, 0x30, 0x5d, 0x73, 0x3b, 0x7c, 0x5d }); this.m_RecvCrypto = new RC4(new byte[] { 0x68, 0x50, 0x76, 0x4a, 0x28, 0x52, 0x7d, 0x4d, 0x70, 0x24, 0x2d, 0x63, 0x67 }); }
//if there is icon/icon.ico, it will be use into public target.exe //-exe target.exe -dir AppFolder -run ToExcuteExe.exe -args arg1 arg2 .. public static void Main(string[] args) { var ZipFile = "data.mhx"; string key = "HinxCor.EncrytoPass"; string tmpCsFile = "se.cs"; string passwd = "F41E6-F565-41F1F-C1DR5-6QW"; ZipHelper.CompressFolder(args[3], ZipFile, 5, passwd); Thread.Sleep(20); string csFile = "code.depub"; var bytes = File.ReadAllBytes(csFile); string csCode = ""; var coder = Encoding.UTF8.GetBytes(key); using (var decrytor = new RC4(coder)) { var decodeData = decrytor.Decrypt((RC4.ByteArray)bytes); csCode = Encoding.UTF8.GetString(decodeData); } csCode = Regex.Replace(csCode, "exeFile", args[5]); csCode = Regex.Replace(csCode, "passwd", passwd); File.WriteAllText(tmpCsFile, csCode); new FileInfo(tmpCsFile).Attributes = FileAttributes.Hidden; Thread.Sleep(25); string batCmd = string.Format(@"@echo off csc -out:{0} {1} -win32icon:{2} -resource:{3},{4}", args[1], tmpCsFile, "icon/icon.ico", "HinxCor.CompressionDot45.dll", ZipFile); Windows.ExecuteCommand(batCmd); }
public void RC4_TestVector_0x0102030405() { byte[] keyStream = ArrayPool <byte> .Shared.Rent(8192); Array.Clear(keyStream); // ArrayPool buffers are not zeroed using var rc4 = new RC4(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }); rc4.Process(keyStream); AssertKeyStreamEqual(keyStream, 0, "b2396305f03dc027ccc3524a0a1118a8"); AssertKeyStreamEqual(keyStream, 16, "6982944f18fc82d589c403a47a0d0919"); AssertKeyStreamEqual(keyStream, 240, "28cb1132c96ce286421dcaadb8b69eae"); AssertKeyStreamEqual(keyStream, 256, "1cfcf62b03eddb641d77dfcf7f8d8c93"); AssertKeyStreamEqual(keyStream, 496, "42b7d0cdd918a8a33dd51781c81f4041"); AssertKeyStreamEqual(keyStream, 512, "6459844432a7da923cfb3eb4980661f6"); AssertKeyStreamEqual(keyStream, 752, "ec10327bde2beefd18f9277680457e22"); AssertKeyStreamEqual(keyStream, 768, "eb62638d4f0ba1fe9fca20e05bf8ff2b"); AssertKeyStreamEqual(keyStream, 1008, "45129048e6a0ed0b56b490338f078da5"); AssertKeyStreamEqual(keyStream, 1024, "30abbcc7c20b01609f23ee2d5f6bb7df"); AssertKeyStreamEqual(keyStream, 1520, "3294f744d8f9790507e70f62e5bbceea"); AssertKeyStreamEqual(keyStream, 1536, "d8729db41882259bee4f825325f5a130"); AssertKeyStreamEqual(keyStream, 2032, "1eb14a0c13b3bf47fa2a0ba93ad45b8b"); AssertKeyStreamEqual(keyStream, 2048, "cc582f8ba9f265e2b1be9112e975d2d7"); AssertKeyStreamEqual(keyStream, 3056, "f2e30f9bd102ecbf75aaade9bc35c43c"); AssertKeyStreamEqual(keyStream, 3072, "ec0e11c479dc329dc8da7968fe965681"); AssertKeyStreamEqual(keyStream, 4080, "068326a2118416d21f9d04b2cd1ca050"); AssertKeyStreamEqual(keyStream, 4096, "ff25b58995996707e51fbdf08b34d875"); ArrayPool <byte> .Shared.Return(keyStream); }
static void Main() { string compress = "lz77"; string eamuse_info = "1-5cf9445d-0dfe"; byte[] data = HexToBytes("93b01743b29ca06e7500db42d83c70843dc776d0617ac96ba0768dd6b457554591d4b8b5f963e12d5fbb5075684c2a9acbfc462aa52686a720c57b3e44373008178684f9fd7ddad3c3a1e9fe1422ae08b9b872520a64cc195a9c04585149ec8de30220345c023663ae916068117ab7d5619362019d18a6f789bbd27e4ee027ce236d2b8d6c0f0917c8990083b741b3958cdf770f970df13088f931da949d1c9f685ba7848a15c3b77083357a6fb430b8a914bf55249f092c2baf14adfa8a7ab6bd430cc6ca5b4a35ea8c893aaa0c88ae6305240d5ae479976caf35e29d943ec628752c191ae40d0998c28e3280b6a55f8198ae"); compress = compress.ToLower(); IEnumerable <byte> decryptedData = data; if (eamuse_info != null) { decryptedData = RC4.ApplyEAmuseInfo(eamuse_info, data); } var rawData = decryptedData; if (compress == "lz77") { rawData = LZ77.Decompress(decryptedData); } else if (compress != "none") { throw new ArgumentException("Unsupported compression algorithm"); } KBinXML kbinxml = new KBinXML(rawData.ToArray()); Console.WriteLine(kbinxml); //GenerateEchidnaSQL(kbinxml); }
public CloudService() { if (rc4 == null) { rc4 = new RC4(); } }
public static byte[] WhatsappDecrypt(byte[] key, byte[] data) { if (encryptionIncoming == null) encryptionIncoming = new RC4(key, 256); byte[] buff = new byte[data.Length]; Buffer.BlockCopy(data, 0, buff, 0, data.Length); encryptionIncoming.Cipher(buff); return buff; }
public HabboCrypto(BigInteger n, BigInteger e, BigInteger d) { this.DH = new DiffieHellman(200); this.RSA = new RSA(n, e, d, 0, 0, 0, 0, 0); this.RC4 = new RC4(); this.Initialized = false; }
public void InitializeChipers(string key) { Encryptor = new RC4(key); Decryptor = new RC4(key); for (int k = 0; k < key.Length; k++) { Encryptor.PRGA(); // skip bytes Decryptor.PRGA(); } }
public SimpleMacEncryptionSend() : base() { MetaData.Name = "Simple Mac Encryption"; MetaData.Version = "0.1.0.0"; MetaData.HelpString = "none"; MetaData.Author = "Brian W. (schizo)"; MetaData.Contact = "*****@*****.**"; MetaData.Description = ""; key = new SHA256Managed().ComputeHash(ASCIIEncoding.ASCII.GetBytes("Dear truck, CODE SOMETHING")); RC4 r = new RC4(); r.Init(key); key = r.GetKeyState(); }
public static byte[] WhatsappEncrypt(byte[] key, byte[] data, bool appendHash) { if(encryptionOutgoing == null) encryptionOutgoing = new RC4(key, 256); HMACSHA1 h = new HMACSHA1(key); byte[] buff = new byte[data.Length]; Buffer.BlockCopy(data, 0, buff, 0, data.Length); encryptionOutgoing.Cipher(buff); byte[] hashByte = h.ComputeHash(buff); byte[] response = new byte[4 + buff.Length]; if (appendHash) { Buffer.BlockCopy(buff, 0, response, 0, buff.Length); Buffer.BlockCopy(hashByte, 0, response, buff.Length, 4); } else { Buffer.BlockCopy(hashByte, 0, response, 0, 4); Buffer.BlockCopy(buff, 0, response, 4, buff.Length); } return response; }
public void loadSeparatedAssets(string projectPath, bool locked) { _projectPath = projectPath; Assets.items.Clear(); string[] packs = Directory.GetFiles(Path.Combine(projectPath), "*.pak"); for (int i = 0; i < packs.Length; i++) { AssetList list = new AssetList(); if (locked) { byte[] key = ByteConverter.GetBytes("dfy3hfi3789y478yhge7y578yrhgiudhr8967498u839udhkjghjk"); RC4 rc4 = new RC4(key); byte[] file = File.ReadAllBytes(packs[i]); file = rc4.Decode(file, file.Length); MemoryStream ms = new MemoryStream(); ms.Write(file, 0, file.Length); ms.Seek(0, SeekOrigin.Begin); list = (AssetList)Serialization.deserialize(ms); ms.Dispose(); } else { list = (AssetList)Serialization.deserialize(packs[i]); } for (int j = 0; j < list.Count; j++) { Assets.items.Add(list[j]); } } if (Assets.items.Count > 0) setReferences(); }
public RC4Encryptor(byte[] key) { rc4In = new RC4(key); rc4Out = new RC4(key); }
public KeyStream(byte[] key, byte[] macKey) { this.rc4 = new RC4(key, 768); this.mac = new HMACSHA1(macKey); }
/// <summary> /// Initializes the chipers with the specified key. /// </summary> /// <param name="key">The key used to update the cipher.</param> private void InitializeCiphers(string key) { Encryptor = new RC4(key); Decryptor = new RC4(key); for (int k = 0; k < key.Length; k++) { // skip bytes Encryptor.PRGA(); Decryptor.PRGA(); } }
/// <summary> /// Runs an RC4 encryption with a specified key /// </summary> /// <param name="xKey"></param> /// <param name="xConfounder"></param> /// <param name="xPayload"></param> /// <returns></returns> public static byte[] RunKerberosEncrypt(byte[] xKey, ref byte[] xConfounder, ref byte[] xPayload) { RC4 xrc4 = new RC4(xKey); return xrc4.KerberosEncrypt(ref xConfounder, ref xPayload); }
/// <summary> /// Runs a Kerberos RC4 encryption on the specified data /// </summary> /// <param name="xKey">Key input</param> /// <param name="xConfounder">outputs the confounder</param> /// <param name="xPayload">Outputs the payload</param> /// <param name="xConLen">Confounder Length</param> /// <param name="xData">Outputs the decrypted data</param> /// <returns></returns> public static bool RunKerberosDecrypt(byte[] xKey, byte[] xData, out byte[] xConfounder, int xConLen, out byte[] xPayload) { RC4 xrc4 = new RC4(xKey); return xrc4.KerberosDecrypt(xData, out xConfounder, xConLen, out xPayload); }
/// <summary> /// Runs an RC4 on the specified data using the specified key /// </summary> /// <param name="xKey"></param> /// <param name="xData"></param> /// <returns></returns> public static byte[] RunAlgorithm(byte[] xKey, byte[] xData) { RC4 xrc4 = new RC4(xKey); return xrc4.RunAlgorithm(xData); }
public Encryptor(string method, string password) { MD5 md5 = System.Security.Cryptography.MD5.Create(); byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(password); byte[] hash = md5.ComputeHash(inputBytes); encryptCTX = IntPtr.Zero; decryptCTX = IntPtr.Zero; this.method = method; this.password = password; if (method != null && method.ToLowerInvariant().Equals("rc4")) { Console.WriteLine("init rc4"); rc4 = new RC4(); encryptTable = rc4.EncryptInitalize(hash); decryptTable = rc4.EncryptInitalize(hash); } else if (method == "table" || method == "" || method == null) { Console.WriteLine("init table"); // TODO endian var a = BitConverter.ToUInt64(hash, 0); for (int i = 0; i < 256; i++) { encryptTable[i] = (byte)i; } for (int i = 1; i < 1024; i++) { encryptTable = mergeSort(encryptTable, a, i); } for (int i = 0; i < 256; i++) { decryptTable[encryptTable[i]] = (byte)i; } } else { initKey(password, method); } }
public void saveAssetsSeparately(string projectPath, bool locked) { if (Assets.items != null) { List<AssetList> packages = new List<AssetList>(); for (int i = 0; i < Assets.items.Count; i++) { Asset asset = Assets.items[i]; AssetList package = findPackage(packages, asset.package); if (package == null) { package = new AssetList(); package.name = asset.package; packages.Add(package); } if (package.name == null) package.name = "Unnamed"; package.Add(asset); } for (int i = 0; i < packages.Count; i++) { string name = Path.Combine(projectPath, packages[i].name.Replace(" ", "_") + ".pak"); Serialization.serialize(name, packages[i]); if (locked) { byte[] key = ByteConverter.GetBytes("dfy3hfi3789y478yhge7y578yrhgiudhr8967498u839udhkjghjk"); RC4 rc4 = new RC4(key); byte[] file = File.ReadAllBytes(name); file = rc4.Encode(file, file.Length); File.WriteAllBytes(name, file); } } } }
private void UpdateSessionStatus(float elapse) { switch (this.status) { case ClientSession.ESessionStatus.ESS_Connect: this.IsConnected = false; if (this.tcpClient.Connect(this.serverHost, this.serverPort)) { this.status = ClientSession.ESessionStatus.ESS_Connecting; this.timeout = Time.time + 15f; } else { this.HandleError(ClientSession.ESessionError.ESE_RequestConnectError, true); } break; case ClientSession.ESessionStatus.ESS_Connecting: if (this.IsConnected) { this.status = ClientSession.ESessionStatus.ESS_Loading; this.timeout = Time.time + 30f; this.decryptKey = null; this.encryptKey = null; this.SendEnterGameMsg(); } else if (Time.time > this.timeout) { this.HandleError(ClientSession.ESessionError.ESE_ConnectTimeout, true); } break; case ClientSession.ESessionStatus.ESS_Loading: if (this.stopTimer) { this.timeout += Time.deltaTime; } if (Time.time > this.timeout) { this.HandleError(ClientSession.ESessionError.ESE_LoadingTimeout, true); } break; case ClientSession.ESessionStatus.ESS_Gaming: if (this.waitingSend) { this.waitingSend = false; ushort msgID = this.requestMsgID; ushort msgSerialID = this.requestSerialID; object ojb = this.requestMsg; this.requestMsgID = 0; this.requestSerialID = 0; this.requestMsg = null; this.Send(msgID, ojb, msgSerialID); } else if (this.requestMsgID != 0 && Time.time - this.timeout > 15f) { this.HandleError(ClientSession.ESessionError.ESE_SendTimeout, true); } if (Time.realtimeSinceStartup - this.heartBeatTimer > 15f && Time.frameCount - this.heartBeatFrame > 300) { this.heartBeatTimer = Time.realtimeSinceStartup; this.heartBeatFrame = Time.frameCount; MC2S_HeartBeat ojb2 = new MC2S_HeartBeat(); this.SendPacket(107, ojb2); } break; } }
private void SetCryptoKey(byte[] CryptoKey) { byte[] array = new byte[16]; byte[] array2 = new byte[16]; if (CryptoKey.Length >= 8) { Array.Copy(CryptoKey, 0, array, 0, 8); } if (CryptoKey.Length >= 16) { Array.Copy(CryptoKey, 8, array2, 0, 8); } if (CryptoKey.Length >= 24) { Array.Copy(CryptoKey, 16, array, 8, 8); } if (CryptoKey.Length >= 32) { Array.Copy(CryptoKey, 24, array2, 8, 8); } this.decryptKey = new RC4(array); this.encryptKey = new RC4(array2); }