コード例 #1
0
 private bool RegisterLicense(string key, string checksum, string serial, string parameter = "licenseData")
 {
     try
     {
         RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
         rsa.FromXmlString(key);
         string     data  = rsa.Encrypt((checksum + "|" + serial).GetBytes(), false).GetString();
         NetRequest query = new NetRequest(scripts[nameof(RegisterLicense)].Address, NetRequest.RequestType.POST, (parameter + "=" + data));
         return(bool.Parse(query.GetResponse()));
     }
     catch (Exception ex) { throw ex; }
 }
コード例 #2
0
 public bool IsChecksumSupported(string key, string checksum, string parameter = "isSupported")
 {
     try
     {
         RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
         rsa.FromXmlString(key);
         string     data  = rsa.Encrypt(checksum.GetBytes(), false).GetString();
         NetRequest query = new NetRequest(scripts[nameof(IsChecksumSupported)].Address, NetRequest.RequestType.POST, (parameter + "=" + data));
         return(bool.Parse(query.GetResponse()));
     }
     catch (Exception ex) { throw ex; }
 }
コード例 #3
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.
        }
コード例 #4
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); }
        }