Skip to content

Repository files navigation

HttpMessageSigning NuGet Package

A .NET implementation of "Signing HTTP Messages" (Cavage, draft 12) for WCF and HttpClient.

Usage

When hooking up HTTP message signing, there's a bunch of configuration options available:

OptionDefaultDescription
AddRecommendedHeaderstrueAutomatically adds recommended headers, such as (request-target), (created), (expires), Date and Digest to HeadersToInclude based on the specification and configuration.
DigestAlgorithmNoneIf set, enables digest calculation of the request body. If AddRecommendedHeaders has been turned off, you also have to add Digest to HeadersToInclude in order to enable the digest calculation.
GetCurrentTimestampDateTimeOffset.UtcNowGets the current UTC timestamp. Useful for testing.
HeadersToIncludeEmptyA set of headers to include in the signature.
ExpiresNoneIf set, enables signature expiry after the specified amount of time.
AddHeaderValueN/AAdds a header with a value to all signed requests and their signatures.
AddHeaderValuesN/AAdds a collection of headers to all signed requests and their signatures.
RequestTargetUriFormatUriFormat.UnescapedGets or sets the URI format used when constructing the (request-target) header.

When using a certificate for signing, there's a convenience method called HttpMessageSigningConfiguration.FromCertificate that can be used to get a configuration with crypto settings based on the certificate.

WCF

To use HTTP message signing with WCF, call UseHttpMessageSigning on your client:

varsignatureAlgorithm=SignatureAlgorithm.Create(rsaOrECDsaAlgorithm);varconfig=newHttpMessageSigningConfiguration("key-id",signatureAlgorithm);usingvarclient=newTheEndpointClient(binding,endpointAddress);client.UseHttpMessageSigning(config);// Make calls using client :)

snippet source | anchor

HttpClient

To use HTTP message signing with HttpClient, create an instance of SigningHttpMessageHandler and pass it when creating the HttpClient instance:

varsignatureAlgorithm=SignatureAlgorithm.Create(rsaOrECDsaAlgorithm);varconfig=newHttpMessageSigningConfiguration("key-id",signatureAlgorithm);varhandler=newSigningHttpMessageHandler(config);usingvarclient=newHttpClient(handler);// Make requests using client :)

snippet source | anchor

About

A .NET implementation of "Signing HTTP Messages" (Cavage, draft 12) for WCF and HttpClient.

Topics

Resources

Stars

6 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages