Skip to content

Instantly share code, notes, and snippets.

@awswithdotnet
Created March 3, 2022 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awswithdotnet/3a73ad15ba9e6821e0ddb19c0a1a0867 to your computer and use it in GitHub Desktop.
Save awswithdotnet/3a73ad15ba9e6821e0ddb19c0a1a0867 to your computer and use it in GitHub Desktop.
kms Client Program Main
private const string RequestUri = "http://localhost:5000/Message";
static async Task Main(string[] args)
{
Console.WriteLine("Enter message:");
var message = Console.ReadLine();
Console.WriteLine("Original:" + message);
IEncrypter encrypter = new AESEncrypter();
IEncryptionPackage encryptionPackage = await encrypter.Encrypt(message);
string jsonString = JsonSerializer.Serialize(encryptionPackage);
using (HttpClient httpClient = new HttpClient())
{
var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("text/plain")
);
HttpResponseMessage response = await httpClient.PostAsync(_requestUri, httpContent);
string decryptedString = await response.Content.ReadAsStringAsync();
Console.Write("Decrypted: " + decryptedString);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment