Last active
September 21, 2021 06:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
IAM secret key to SMTP password
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ping back https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html