public static byte[] Decrypt(byte[] Payload, KeyPair keyPair) { ushort Id; int Length; ushort Version; using (Reader reader = new Reader(Payload)) { Id = reader.ReadUInt16(); Length = reader.ReadInt24(); Version = reader.ReadUInt16(); Payload = Payload.Skip(2).Skip(3).Skip(2).ToArray(); } if (!Form1.Config.UseRC4) { switch (Id) { case 20100: decryptedPayload = Payload; break; case 20103: decryptedPayload = Payload; break; case 20104: ClientConfig.ServerNonce = GenericHash.Hash(ClientConfig.SNonce.Concat(keyPair.PublicKey).Concat(Keys.ServerKey).ToArray(), null, 24); decryptedPayload = PublicKeyBox.Open(Payload, ClientConfig.ServerNonce, keyPair.PrivateKey, Keys.ServerKey); ClientConfig.RNonce = decryptedPayload.Take(24).ToArray(); ClientConfig.SharedKey = decryptedPayload.Skip(24).Take(32).ToArray(); decryptedPayload = decryptedPayload.Skip(24).Skip(32).ToArray(); break; default: ClientConfig.RNonce = Utilities.Increment(Utilities.Increment(ClientConfig.RNonce)); byte[] toDecrypt = new byte[16].Concat(Payload).ToArray(); decryptedPayload = SecretBox.Open(toDecrypt, ClientConfig.RNonce, ClientConfig.SharedKey); Logger.Write(Encoding.UTF8.GetString(decryptedPayload), "Decrypted OHD"); break; } } else if (Form1.Config.UseRC4) { decryptedPayload = RC4.Decrypt(Payload); } else { } return(decryptedPayload); }
public static byte[] Decrypt(byte[] encrypted) { byte[] decrypted; ushort id; int length; ushort version; using (var reader = new Reader(encrypted)) { id = reader.ReadUInt16(); length = reader.ReadInt24(); version = reader.ReadUInt16(); } encrypted = encrypted.Skip(2).Skip(3).Skip(2).ToArray(); switch (id) { case 10100: decrypted = encrypted; break; case 10101: ServerConfig.clientPublicKey = encrypted.Take(32).ToArray(); encrypted = encrypted.Skip(32).ToArray(); ServerConfig.clientSharedKey = ServerConfig.clientPublicKey; ServerConfig.clientRNonce = Utils.GenerateRandomBytes(24); byte[] nonce = GenericHash.Hash(ServerConfig.clientPublicKey.Concat(Keys.ServerKey).ToArray(), null, 24); decrypted = PublicKeyBox.Open(encrypted, nonce, ServerConfig.privateKey, ServerConfig.clientPublicKey); ServerConfig.clientSessionKey = decrypted.Take(24).ToArray(); ServerConfig.clientSNonce = decrypted.Skip(24).Take(24).ToArray(); ServerConfig.clientSNonce = ServerConfig.clientSNonce; decrypted = decrypted.Skip(24).Skip(24).ToArray(); Console.WriteLine(BitConverter.ToString(ServerConfig.clientSNonce).Replace("-", "")); Console.WriteLine(BitConverter.ToString(ServerConfig.clientSessionKey).Replace("-", "")); Console.WriteLine(BitConverter.ToString(nonce).Replace("-", "")); Console.WriteLine(BitConverter.ToString(ServerConfig.clientPublicKey).Replace("-", "")); break; default: ServerConfig.clientSNonce = Utilities.Increment(Utilities.Increment(ServerConfig.clientSNonce)); decrypted = SecretBox.Open(new byte[16].Concat(encrypted).ToArray(), ServerConfig.clientSNonce, ServerConfig.clientSharedKey); break; } return(decrypted); }