Exemplo n.º 1
0
        public static string HashSHA256File(string path)
        {
            SHA256 Sha256 = SHA256.Create();

            using (FileStream stream = File.OpenRead(path))
            {
                byte[] bytes = Sha256.ComputeHash(stream);

                return(ExtensionsString.BytesToHex(bytes));
            }
        }
Exemplo n.º 2
0
        public static void Connect(TcpClient client, string host, int controlPort, string controlPassword)
        {
            if (client == null)
            {
                throw new Exception("Internal error (client is null)");
            }

            bool controlAuthenticate = Engine.Instance.Storage.GetBool("proxy.tor.control.auth");

            byte[] password = System.Text.Encoding.ASCII.GetBytes(controlPassword);

            if (controlAuthenticate)
            {
                if (controlPassword == "")
                {
                    Init();

                    if (m_torCookiePath == "")
                    {
                        throw new Exception(LanguageManager.GetText("TorControlNoPath"));
                    }

                    Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("TorControlAuth", "Cookie, from " + m_torCookiePath));

                    password = m_torCookiePassword;
                }
                else
                {
                    Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("TorControlAuth", "Password"));
                }
            }

            client.Connect(host, controlPort);

            if (controlAuthenticate)
            {
                Write(client, "AUTHENTICATE ");
                Write(client, ExtensionsString.BytesToHex(password));
                Write(client, "\n");

                string result = Read(client);

                if (result != "250 OK")
                {
                    throw new Exception(result);
                }
            }

            Flush(client);
        }