Skip to content

Instantly share code, notes, and snippets.

@shrys
Last active September 21, 2021 06:39
Show Gist options
  • Save shrys/51c911233e871b4a676d8467312b8226 to your computer and use it in GitHub Desktop.
Save shrys/51c911233e871b4a676d8467312b8226 to your computer and use it in GitHub Desktop.
C# implementation to obtain smtp password from signed secret key for AWS SES
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(GetCredential("YOUR_SECRET_KEY"));
}
private static byte[] sign(byte[] key, string value)
{
return new System.Security.Cryptography.HMACSHA256(key).ComputeHash(System.Text.Encoding.UTF8.GetBytes(value));
}
private static string GetCredential(string secret, string region = "us-east-1") //'us-east-1','us-west-2','eu-west-1'
{
string DATE = "11111111";
string SERVICE = "ses";
string MESSAGE = "SendRawEmail";
string TERMINAL = "aws4_request";
byte[] VERSION = new byte[] { 0x04 };
var signature = sign(System.Text.Encoding.UTF8.GetBytes("AWS4" + secret), DATE);
signature = sign(signature, region);
signature = sign(signature, SERVICE);
signature = sign(signature, TERMINAL);
signature = sign(signature, MESSAGE);
var signatureAndVersion = VERSION.Concat(signature).ToArray();
return System.Convert.ToBase64String(signatureAndVersion);
}
}
@shrys
Copy link
Author

shrys commented May 16, 2019

@shrys
Copy link
Author

shrys commented May 16, 2019

IAM secret key to SMTP password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment