コード例 #1
0
        static void MessageReceived(HS_SocketDataWorker sdw, string message)
        {
            //Decrypt
            string       json    = RSAHandler.Decrypt(private_key, message);
            LoginRequest request = LoginRequest.Parse(json);

            Console.WriteLine(json);

            //Check login
            //TODO make this async
            string stringResponse = NetUtil.PostSynchro(Settings.Current.InternalLoginUrl,
                                                        new System.Collections.Generic.Dictionary <string, string>()
            {
                { "code", Settings.Current.InternalApiAccessCode }, { "userid", request.Username },
                { "password", request.Password }, { "key", request.Key }
            });
            ServerResponse response = ServerResponse.Parse(stringResponse);

            Log(stringResponse);

            if (response != null)
            {
                if (response.Result == "success")
                {
                    Log("success sending back");
                    string sec = Convert.ToBase64String(TDESHandler.Encrypt(request.Key, stringResponse));
                    sdw.Send(sec);
                }
                else
                {
                }
            }
        }
コード例 #2
0
 public static void RSA_UnitTest()
 {
     for (int i = 0; i < 1000000; i++)
     {
         String[] keys       = RSAHandler.GenerateKeyPair(1024);
         String   publickey  = keys[0];
         String   privatekey = keys[1];
         String   data       = GenerateRandomString(78);
         string   cypher     = RSAHandler.Encrypt(publickey, data);
         string   text       = RSAHandler.Decrypt(privatekey, cypher);
         if (data != text)
         {
             Console.WriteLine("\n\nFailed!");
             Console.WriteLine("Data: " + data);
             Console.WriteLine("Text: " + text);
             for (int a = 0; a < data.Length; a++)
             {
                 if (data[a] != text[a])
                 {
                     int x = data[a];
                     int y = text[a];
                     int z = 0;
                 }
             }
             File.WriteAllText("err_dump.txt", data);
             return;
         }
         else
         {
             Console.WriteLine(i + " passed! " + data.Substring(0, (data.Length < 10) ? data.Length : 10));
         }
     }
     Console.WriteLine("Test passed!");
 }