Egov.XmlSigning
10.0.1
Prefix Reserved
See the version list below for details.
dotnet add package Egov.XmlSigning --version 10.0.1
NuGet\Install-Package Egov.XmlSigning -Version 10.0.1
<PackageReference Include="Egov.XmlSigning" Version="10.0.1" />
<PackageVersion Include="Egov.XmlSigning" Version="10.0.1" />
<PackageReference Include="Egov.XmlSigning" />
paket add Egov.XmlSigning --version 10.0.1
#r "nuget: Egov.XmlSigning, 10.0.1"
#:package Egov.XmlSigning@10.0.1
#addin nuget:?package=Egov.XmlSigning&version=10.0.1
#tool nuget:?package=Egov.XmlSigning&version=10.0.1
Egov.XmlSigning
A .NET library providing extension methods for signing, verifying, encrypting and decrypting SOAP envelopes and XML documents according to the WS-Security standard. It targets .NET 10.0+.
Table of Contents
- Features
- Prerequisites
- Installation
- Usage
- Testing
- Changelog
- Contributing
- Code of Conduct
- AI Assistance
- License
Features
- WS-Security signing and signature validation for SOAP envelopes
- Envelope encryption and decryption, including optional signature encryption
- Message freshness checks via time-to-live and allowed clock skew
- Works with both
XDocumentandXmlDocument - Conversion and traversal helpers between the two XML APIs
Prerequisites
- .NET 10.0 SDK or later
- An X.509 certificate with a private key for signing/decryption, and the counterparty's public certificate for verification/encryption
Installation
dotnet add package Egov.XmlSigning
Usage
Signing a SOAP Envelope
using Egov.XmlSigning.Soap;
var envelope = XDocument.Parse(soapXml);
var signed = envelope.SignSoapEnvelope(privateCertificate, timeToLive: TimeSpan.FromMinutes(5));
timeToLive stamps the WS-Security timestamp the recipient validates against. Two optional
parameters are available: useSha1 (defaults to false — leave it off unless a legacy
counterparty demands SHA-1) and tokenReference, which selects how the signing certificate
is referenced (BinarySecurityToken by default).
Verifying a Signature
using Egov.XmlSigning.Soap;
var isValid = envelope.ValidateSoapEnvelopeSignature(
trustedCertificates: [partnerPublicCertificate],
timeToLive: TimeSpan.FromMinutes(5),
allowedClockSkew: TimeSpan.FromMinutes(10));
if (!isValid)
{
throw new SecurityException("SOAP envelope signature is not valid.");
}
timeToLive bounds how long a signed message stays acceptable; allowedClockSkew tolerates clock drift between the two systems. Both must be supplied deliberately — do not widen them to work around a clock problem you have not diagnosed.
Encryption and Decryption
using Egov.XmlSigning.Soap;
// Encrypt for the recipient, including the signature by default.
var encrypted = envelope.EncryptSoapEnvelope(recipientPublicCertificate);
// Encrypt leaving the signature in the clear.
var partiallyEncrypted = envelope.EncryptSoapEnvelope(recipientPublicCertificate, encryptSignature: false);
// Decrypt with your own private key.
var decrypted = encrypted.DecryptSoapEnvelope(privateCertificate);
XML Helpers
Egov.XmlSigning.Xml provides conversion between XDocument and XmlDocument (XmlConversionExtensions) and element traversal helpers (XElementExtensions), useful when bridging APIs that expect one representation or the other.
Testing
dotnet test src/Egov.XmlSigning.sln
The test project uses NUnit and ships self-signed certificates under src/Egov.XmlSigning.Tests/Certificates/ for round-trip signing and encryption tests. These are test fixtures only and must never be used outside the test suite.
Changelog
See CHANGELOG.md for what changed in each release.
Contributing
See CONTRIBUTING.md.
Code of Conduct
See CODE_OF_CONDUCT.md.
AI Assistance
See AGENTS.md for guidance aimed at AI coding assistants.
License
Distributed under the MIT License. See LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Egov.Extensions.Configuration (>= 10.0.5)
- System.Security.Cryptography.Pkcs (>= 10.0.12)
- System.Security.Cryptography.Xml (>= 10.0.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.