Class Aws4HmacFields
- Namespace
- Codebelt.Extensions.AwsSignature4
- Assembly
- Codebelt.Extensions.AwsSignature4.dll
A collection of constants for Aws4HmacAuthorizationHeaderBuilder and related.
public static class Aws4HmacFields
- Inheritance
-
Aws4HmacFields
Examples
Examples
This example demonstrates using the Aws4HmacFields constants to construct AWS Signature Version 4 credential scope and authorization header components:
using System;
using Codebelt.Extensions.AwsSignature4;
namespace Aws4Example;
class Program
{
static void Main()
{
var timestamp = DateTime.UtcNow;
var region = "us-east-1";
var service = "s3";
var clientId = "AKIAIOSFODNN7EXAMPLE";
// Access Aws4HmacFields constants to build the credential scope
var dateStamp = timestamp.ToAwsDateString();
var credentialScope = $"{dateStamp}/{region}/{service}/{Aws4HmacFields.Aws4Request}";
// Format the Authorization header using Aws4HmacFields.Scheme
var signedHeaders = "host;x-amz-date;x-amz-content-sha256";
var signature = "computed-signature-hex-string";
var authorizationHeaderValue = $"{Aws4HmacFields.Scheme} Credential={clientId}/{credentialScope}, SignedHeaders={signedHeaders}, Signature={signature}";
// Retrieve other Aws4HmacFields constants for date formatting
var dateTimeStampFormat = Aws4HmacFields.DateTimeStampFormat;
var dateStampFormat = Aws4HmacFields.DateStampFormat;
var dateTimeStamp = timestamp.ToString(dateTimeStampFormat);
Console.WriteLine($"Scheme: {Aws4HmacFields.Scheme}");
Console.WriteLine($"Date-Time Stamp Format: {dateTimeStampFormat}");
Console.WriteLine($"Date-Time Stamp: {dateTimeStamp}");
Console.WriteLine($"Credential Scope: {credentialScope}");
Console.WriteLine($"Authorization Header: {authorizationHeaderValue}");
}
}
Fields
Aws4Request
The final part of the signing key tied to a CredentialScope.
public const string Aws4Request = "aws4_request"
Field Value
DateStamp
The date only value of the request expressed as, what Amazon calls, an ISO8601 basic date format.
public const string DateStamp = "iso8601BasicDateFormat"
Field Value
Remarks
DateStampFormat
The AWS date only format used when converting a DateTime value to its equivalent string representation.
public const string DateStampFormat = "yyyyMMdd"
Field Value
Remarks
DateTimeStamp
The date-time value of the request expressed as, what Amazon calls, an ISO8601 basic date time format.
public const string DateTimeStamp = "iso8601BasicDateTimeFormat"
Field Value
Remarks
DateTimeStampFormat
The AWS date-time format used when converting a DateTime value to its equivalent string representation.
public const string DateTimeStampFormat = "yyyyMMddTHHmmssZ"
Field Value
Remarks
Region
The region part of the signing key tied to a CredentialScope.
public const string Region = "awsRegion"
Field Value
Scheme
The authentication scheme of the Aws4HmacAuthorizationHeader.
public const string Scheme = "AWS4-HMAC-SHA256"
Field Value
Remarks
Service
The service part of the signing key tied to a CredentialScope.
public const string Service = "awsService"