Exemplo n.º 1
0
        public bool IsKeyValid(string key, string parameter = "ping", string data = "pong")
        {
            // Play ping-pong to get a score.
            NetRequest game  = new NetRequest(scripts[nameof(IsKeyValid)].Address, NetRequest.RequestType.POST, (parameter + "=" + data));
            string     score = game.GetResponse();

            // Try to decrypt our score.
            if (DecryptData(key, Encoding.ASCII.GetBytes(score)))
            {
                return(true); // The key is good... obviously...
            }
            return(false);    // The key could not be authenticated.
        }
Exemplo n.º 2
0
        /// <summary>
        /// Obtains a blacklist from a webserver using a PHP script and the provided <see cref="RSACryptoServiceProvider"/> public key.
        /// </summary>
        /// <param name="key">The public key to used to use for cryptographic transformations.</param>
        private string[] GetBlacklist(string key)
        {
            // Import our public key.
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

            rsa.FromXmlString(key);

            // Encrypt a chunk of data so our server can verify it's really us.
            string     data     = (rsa.Encrypt(("Hello").GetBytes(), false)).GetString();
            NetRequest request  = new NetRequest(Website, NetRequest.RequestType.POST, "chunk=" + data);
            string     response = request.GetResponse();

            // Try to decrypt the server's response so we can verify it's really the server.
            try
            {
                string   decrypted = (rsa.Decrypt(response.GetBytes(), false)).GetString();
                string[] blacklist = decrypted.Split('|');
                return(blacklist);
            }
            catch { return(null); }
        }