Exemple #1
0
        private void buttonEncode_Click(object sender, EventArgs e)
        {
            try
            {
                switch (algorithm)
                {
                case Algorithm.Base64Unicode:
                    textBoxEncode.Text = TranString.EncodeBase64Unicode(textBoxDecode.Text);
                    break;

                case Algorithm.Base64:
                    textBoxEncode.Text = TranString.EncodeBase64(textBoxDecode.Text);
                    break;

                case Algorithm.UrlEncode:
                    textBoxEncode.Text = TranString.EncodeUrlEncode(textBoxDecode.Text);
                    break;

                case Algorithm.AES:
                    textBoxEncode.Text = TranString.EncodeAES(textBoxDecode.Text, textBoxKey.Text);
                    break;

                case Algorithm.Rijndael:
                    textBoxEncode.Text = TranString.EncodeRijndael(textBoxDecode.Text, textBoxRijndaelKey.Text, textBoxRijndaelVector.Text);
                    break;

                default:
                    throw new ArgumentOutOfRangeException($"algorithm : {algorithm}");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #2
0
 private async Task DbSave()
 {
     try
     {
         foreach (DataGridViewRow item in dgvServerList.Rows)
         {
             if (bool.Parse(item.Cells["CheckBox"].Value.ToString()))
             {
                 string publicIp = item.Cells["PublicIp"].Value.ToString();
                 if (publicIp == null && publicIp.Length == 0)
                 {
                     throw new Exception("publicip is null");
                 }
                 else
                 {
                     var p = new List <KeyValuePair <string, string> >();
                     p.Add(new KeyValuePair <string, string>("serverName", item.Cells["Name"].Value.ToString()));
                     p.Add(new KeyValuePair <string, string>("serverInstanceNo", item.Cells["InstanceNo"].Value.ToString()));
                     p.Add(new KeyValuePair <string, string>("serverPublicIp", item.Cells["PublicIp"].Value.ToString()));
                     p.Add(new KeyValuePair <string, string>("serverPrivateIp", item.Cells["PrivateIp"].Value.ToString()));
                     p.Add(new KeyValuePair <string, string>("serverPort", textBoxPort.Text.Trim()));
                     p.Add(new KeyValuePair <string, string>("serverUserId", textBoxId.Text.Trim()));
                     p.Add(new KeyValuePair <string, string>("serverPassword", TranString.EncodeRijndael(
                                                                 textBoxPassword.Text.Trim(),
                                                                 LogClient.Config.Instance.GetCryptionKey()
                                                                 )));
                     await fileDb.UpSertTable(FileDb.TableName.TBL_SERVER, p);
                 }
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemple #3
0
        private async Task <WcfResponse> SqlConnectionStringSetting(string publicIp)
        {
            await Execute(@"$FileName = 'c:\temp\lazylog.mdf'
if (Test-Path $FileName) {
  Remove-Item $FileName -Force
}", publicIp);
            await Execute(@"$FileName = 'c:\temp\lazylog_log.ldf'
if (Test-Path $FileName) {
  Remove-Item $FileName -Force
}", publicIp);

            WcfResponse   wcfResponse = new WcfResponse();
            Task <string> taskString;
            string        response = string.Empty;

            var TypeConfigSetting = new
            {
                ConfigFile = "LogClientConfig.txt",
                Category   = "Encryption",
                Key        = "GetCryptionKey",
                Value      = LogClient.Config.Instance.GetValue(LogClient.Category.Encryption, LogClient.Key.GetCryptionKey)
            };

            var    jt      = JToken.Parse(JsonConvert.SerializeObject(TypeConfigSetting));
            string command = jt.ToString(Newtonsoft.Json.Formatting.Indented);

            taskString = dataManager.Execute
                             ("ExecuterRest"
                             , "TypeConfigSetting"
                             , command
                             , CsLib.RequestType.POST
                             , $"https://{publicIp}:9090"
                             , @"/LazyServer/LazyCommand/PostCmd"
                             , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey)
                             , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)
                             , 60);

            response    = await taskString;
            wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(response);

            if (!wcfResponse.IsSuccess)
            {
                MessageBox.Show(wcfResponse.ResultMessage + wcfResponse.ErrorMessage);
            }

            // start
            TypeConfigSetting = new
            {
                ConfigFile = "LogClientConfig.txt",
                Category   = "Encryption",
                Key        = "GetCryptionKeyUrl",
                Value      = LogClient.Config.Instance.GetValue(LogClient.Category.Encryption, LogClient.Key.GetCryptionKeyUrl)
            };

            jt      = JToken.Parse(JsonConvert.SerializeObject(TypeConfigSetting));
            command = jt.ToString(Newtonsoft.Json.Formatting.Indented);

            taskString = dataManager.Execute
                             ("ExecuterRest"
                             , "TypeConfigSetting"
                             , command
                             , CsLib.RequestType.POST
                             , $"https://{publicIp}:9090"
                             , @"/LazyServer/LazyCommand/PostCmd"
                             , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey)
                             , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)
                             , 60);

            response    = await taskString;
            wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(response);

            if (!wcfResponse.IsSuccess)
            {
                MessageBox.Show(wcfResponse.ResultMessage + wcfResponse.ErrorMessage);
            }
            // end



            TypeConfigSetting = new
            {
                ConfigFile = "LogClientConfig.txt",
                Category   = "Encryption",
                Key        = "KeyTag",
                Value      = LogClient.Config.Instance.GetValue(LogClient.Category.Encryption, LogClient.Key.KeyTag)
            };

            jt      = JToken.Parse(JsonConvert.SerializeObject(TypeConfigSetting));
            command = jt.ToString(Newtonsoft.Json.Formatting.Indented);

            taskString = dataManager.Execute
                             ("ExecuterRest"
                             , "TypeConfigSetting"
                             , command
                             , CsLib.RequestType.POST
                             , $"https://{publicIp}:9090"
                             , @"/LazyServer/LazyCommand/PostCmd"
                             , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey)
                             , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)
                             , 60);

            response    = await taskString;
            wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(response);

            if (!wcfResponse.IsSuccess)
            {
                MessageBox.Show(wcfResponse.ResultMessage + wcfResponse.ErrorMessage);
            }



            TypeConfigSetting = new
            {
                ConfigFile = "LogClientConfig.txt",
                Category   = "Encryption",
                Key        = "Ciphertext",
                Value      = LogClient.Config.Instance.GetValue(LogClient.Category.Encryption, LogClient.Key.Ciphertext)
            };

            jt      = JToken.Parse(JsonConvert.SerializeObject(TypeConfigSetting));
            command = jt.ToString(Newtonsoft.Json.Formatting.Indented);

            taskString = dataManager.Execute
                             ("ExecuterRest"
                             , "TypeConfigSetting"
                             , command
                             , CsLib.RequestType.POST
                             , $"https://{publicIp}:9090"
                             , @"/LazyServer/LazyCommand/PostCmd"
                             , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey)
                             , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)
                             , 60);

            response    = await taskString;
            wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(response);

            if (!wcfResponse.IsSuccess)
            {
                MessageBox.Show(wcfResponse.ResultMessage + wcfResponse.ErrorMessage);
            }



            TypeConfigSetting = new
            {
                ConfigFile = "LogClientConfig.txt",
                Category   = "Encryption",
                Key        = "LocalCryptionKey",
                Value      = LogClient.Config.Instance.GetValue(LogClient.Category.Encryption, LogClient.Key.LocalCryptionKey)
            };

            jt      = JToken.Parse(JsonConvert.SerializeObject(TypeConfigSetting));
            command = jt.ToString(Newtonsoft.Json.Formatting.Indented);

            taskString = dataManager.Execute
                             ("ExecuterRest"
                             , "TypeConfigSetting"
                             , command
                             , CsLib.RequestType.POST
                             , $"https://{publicIp}:9090"
                             , @"/LazyServer/LazyCommand/PostCmd"
                             , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey)
                             , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)
                             , 60);

            response    = await taskString;
            wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(response);

            if (!wcfResponse.IsSuccess)
            {
                MessageBox.Show(wcfResponse.ResultMessage + wcfResponse.ErrorMessage);
            }



            TypeSqlIdPassSetting typeSqlIdPassSetting = new TypeSqlIdPassSetting
            {
                SqlId = textBoxId.Text,
                SqlEncryptedPassword = TranString.EncodeRijndael(textBoxPassword.Text, LogClient.Config.Instance.GetCryptionKey()),
                SqlDataSource        = ".",
                SqlConnectTimeout    = "5"
            };

            string cmdText        = JsonConvert.SerializeObject(typeSqlIdPassSetting);
            string responseString = string.Empty;

            try
            {
                var task = dataManager.Execute
                               ("ExecuterRest"
                               , "TypeSqlIdPassSetting"
                               , cmdText
                               , CsLib.RequestType.POST
                               , $"https://{publicIp}:9090"
                               , @"/LazyServer/LazyCommand/PostCmd"
                               , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey)
                               , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey));

                response    = await task;
                wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(response);
            }
            catch (Exception)
            {
                throw;
            }
            return(wcfResponse);
        }