private void CheckConfigurationKey() { AppendVerifyLog("*. Encrytpion Key"); string getCryptionKeyType = logClientConfig.GetValue(LogClient.Category.Encryption, LogClient.Key.GetCryptionKey); string keyTag = LogClient.Config.Instance.GetValue(LogClient.Category.Encryption, LogClient.Key.KeyTag); string ciphertext = LogClient.Config.Instance.GetValue(LogClient.Category.Encryption, LogClient.Key.Ciphertext); try { AppendVerifyLog($" Current Encrytpion Type : {getCryptionKeyType}"); if (getCryptionKeyType.Equals("Local", StringComparison.OrdinalIgnoreCase)) { AppendVerifyLog(" Cryption Key : " + logClientConfig.GetValue(Category.Encryption, Key.LocalCryptionKey)); if (logClientConfig.GetValue(Category.Encryption, Key.LocalCryptionKey).Length == 0) { AppendVerifyLog($" [Warning] Cryption Key is too short! (key length is : {logClientConfig.GetValue(Category.Encryption, Key.LocalCryptionKey).Length})"); } } else { if (keyTag.Length <= 1) { throw new Exception(" [ERROR] The KMS keytag is not corrent!"); } if (ciphertext.Length <= 1) { throw new Exception(" [ERROR] The KMS ciphertext is not corrent!"); } var kmsDecrypteParameters = new { ciphertext = ciphertext }; var jt = JToken.Parse(JsonConvert.SerializeObject(kmsDecrypteParameters)); string parameters = jt.ToString(Newtonsoft.Json.Formatting.Indented); SoaCall asyncCall = new SoaCall(); var response = AsyncHelpers.RunSync <string>(() => asyncCall.WebApiCall( @"https://kms.apigw.ntruss.com", RequestType.POST, @"/keys/v2/" + keyTag + @"/decrypt", parameters, LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey), LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey), 5)); JsonSerializerSettings options = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }; if (!response.Contains("SUCCESS")) { throw new Exception(response); } KmsDecryptResponse KmsDecryptResponse = JsonConvert.DeserializeObject <KmsDecryptResponse>(response, options); AppendVerifyLog(" Cryption KMS key : " + TranString.DecodeBase64(KmsDecryptResponse.data.plaintext)); } AppendVerifyLog($" Encryption Key Check Result : Success"); } catch (Exception ex) { AppendVerifyLog(ex.Message); AppendVerifyLog(" Encryption Key(KMS) Help Message..."); AppendVerifyLog(" -----------------------------------------------"); AppendVerifyLog(" 1. Enable subaccount in MC Console."); AppendVerifyLog(" 2. In the Management Console, create a key for encryption / decryption."); AppendVerifyLog(" 3. Paste the generated keytag into the SQL Server DBA Tool."); AppendVerifyLog(" 4. In the SQL Server DBA Tool, type key"); AppendVerifyLog(" 5. Create ciphertext in the SQL Server DBA Tool."); AppendVerifyLog(" 6. Save."); AppendVerifyLog(" -----------------------------------------------"); throw new Exception("Encryption Key Error!"); } }
private void buttonKeyTest_Click(object sender, EventArgs e) { if (radioButtonLocalKey.Checked) { MessageBox.Show(logClientConfig.GetValue(Category.Encryption, Key.LocalCryptionKey)); } else //(radioButtonNcpKms.Checked) { try { if (textBoxKeyTag.Text.Trim().Length == 0) { throw new Exception("keytag is empty. Please enter keytag"); } if (textBoxCiphertext.Text.Trim().Length == 0) { throw new Exception("ciphertext is empty. Please enter ciphertext"); } var kmsDecrypteParameters = new { ciphertext = textBoxCiphertext.Text }; var jt = JToken.Parse(JsonConvert.SerializeObject(kmsDecrypteParameters)); string parameters = jt.ToString(Newtonsoft.Json.Formatting.Indented); SoaCall asyncCall = new SoaCall(); var response = AsyncHelpers.RunSync <string>(() => asyncCall.WebApiCall( @"https://kms.apigw.ntruss.com", RequestType.POST, @"/keys/v2/" + textBoxKeyTag.Text + @"/decrypt", parameters, textBoxAccessKey.Text.Trim(), textBoxSecretKey.Text.Trim(), 5)); JsonSerializerSettings options = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }; if (!response.Contains("SUCCESS")) { throw new Exception(response); } KmsDecryptResponse KmsDecryptResponse = JsonConvert.DeserializeObject <KmsDecryptResponse>(response, options); MessageBox.Show(TranString.DecodeBase64(KmsDecryptResponse.data.plaintext)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //else //{ // try // { // SoaCall asyncCall = new SoaCall(); // var key = AsyncHelpers.RunSync<string>(() => asyncCall.WebApiCall( // textBoxRemoteKeyServerUrl.Text.Trim(), // RequestType.GET, // textBoxAction.Text.Trim(), // textBoxAccessKey.Text.Trim(), // textBoxSecretKey.Text.Trim(), 5)); // if (key.Contains("Endpoint not found.")) // { // throw new Exception("Endpoint not found."); // } // key = TranString.DecodeBase64((key.Replace("\"", ""))); // if (key.Equals("")) // MessageBox.Show("authentication error, check accessKey and secretKey"); // else // MessageBox.Show(key); // } // catch (Exception ex) // { // if (ex.Message.Contains("A task was canceled.")) // { // MessageBox.Show("Unable to connect to the remote server"); // return; // } // if (ex.InnerException != null) // { // MessageBox.Show(ex.InnerException.Message); // } // else // { // MessageBox.Show(ex.Message); // } // } //} }