NSign signature providers for signing and verifying signatures (RFC 9421). See also: https://datatracker.ietf.org/doc/rfc9421/
$ dotnet add package NSign.SignatureProvidersSignature providers for signing and verifying signatures with NSign. This library currently supports both asymmetric
algorithms (using public-key cryptography) and symmetric algorithms (using HMAC). Signature providers typically
implement both the ISigner and the IVerifier interfaces, but implementation can also be split into separate classes.
Currently, the following asymmetrics signature algorithms are supported:
ecdsa-p256-sha256 in 1), in class ECDsaP256Sha256SignatureProviderecdsa-p384-sha384 in 1), in class ECDsaP382Sha384SignatureProviderrsa-pss-sha512 in 1) in class RsaPssSha512SignatureProviderrsa-v1_5-sha256 in 1) in class RsaPkcs15Sha256SignatureProviderThese signature providers can all be created by passing an instance of X509Certificate2 and having the provider
extract the public key for signature verification from there. If the provider is to be used for signing, the certificate
that is provided must have a private key too, otherwise signing will fail / an exception will be thrown. Naturally,
the keys used in the certificate must match the key parameters/formats expected by the signature provider.
For instance, to use rsa-pss-sha512 with a PEM-encoded certificate in a file called the-cert.cer for signature
verification, creating the provider as follows will do:
var provider = new RsaPssSha512SignatureProvider(
new X509Certificate2("the-cert.cer"),
"the-cert-key-id"))
To use rsa-pss-sha512 with a PFX file called the-cert.pfx, holding the private key for message signing, a provider
can be created as follows:
var provider = new RsaPssSha512SignatureProvider(
new X509Certificate2("the-cert.pfx", "here-goes-the-password-to-the-PFX"),
"the-cert-key-id"))
Due to their nature, asymmetric signatures are often preferable over symmetric signatures because they do not require both the signing and verifying party to share a secret (the key). Instead, the public key can be published anywhere / through any means for verifiers to download and use.
Currently, the following symmetric signature algorithms are supported:
hmac-sha256 in 1), in class HmacSha256SignatureProviderThis signature provider requires the (shared) key to be provided during construction.
See also: