Path: redb-route/redb.Route.Soap/SoapBase64.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Soap/SoapBase64.cs ---- using System.Security.Cryptography.Xml; using System.Xml; using redb.Route.Serialization; namespace redb.Route.Soap; /// /// The base64 values of an XML Signature or XML Encryption element are XML Schema base64Binary, whose lexical /// space has no value with non-zero unused bits in its last character. .NET 11 refuses such a value inside /// and , .NET 10 decodes it; checking it before they run makes a /// SOAP endpoint refuse it on every runtime. /// internal static class SoapBase64 { private const string Base64Encoding = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"; private static readonly HashSet DsBase64 = new(StringComparer.Ordinal) { "DigestValue", "SignatureValue", "X509Certificate", "X509SKI", "X509CRL", "Modulus", "Exponent", "P", "Q", "G", "Y", "J", "Seed", "PgenCounter", "PGPKeyID", "PGPKeyPacket", "SPKISexp", }; private static readonly HashSet XencBase64 = new(StringComparer.Ordinal) { "CipherValue", "OAEPparams", "KA-Nonce" }; private static readonly HashSet WsseBase64 = new(StringComparer.Ordinal) { "BinarySecurityToken", "KeyIdentifier" }; /// /// The first base64 element under (itself included) whose value has non-zero unused bits, /// or null when there is none. /// public static XmlElement? FirstNonCanonical(XmlElement root) { if (IsNonCanonical(root)) return root; foreach (var node in root.GetElementsByTagName("*")) if (node is XmlElement element && IsNonCanonical(element)) return element; return null; } private static bool IsNonCanonical(XmlElement element) { var base64 = element.NamespaceURI switch { SignedXml.XmlDsigNamespaceUrl => DsBase64.Contains(element.LocalName), SoapEncryption.XmlEncNs => XencBase64.Contains(element.LocalName), SoapSecurity.WsseNs => WsseBase64.Contains(element.LocalName) && element.GetAttribute("EncodingType") is "" or Base64Encoding, _ => false, }; return base64 && Base64Text.HasUnusedBitsSet(element.InnerText); } }