{"record":{"id":"9d2ad6340ad1b051","repo":"dotnet/wpf","slug":"unsupported-hash-algorithm-specified","errorCode":null,"errorMessage":"Unsupported hash algorithm specified.","messagePattern":"Unsupported hash algorithm specified\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs","lineNumber":204,"sourceCode":"        }\n\n        /// <summary>\n        /// Hashalgorithm to use when creating/verifying signatures\n        /// </summary>\n        /// <value></value>\n        /// <remarks>defaults to SHA1</remarks>\n        public String HashAlgorithm\n        {\n            get\n            {\n                return _hashAlgorithmString;\n            }\n            set\n            {\n                ArgumentNullException.ThrowIfNull(value);\n\n                if (value.Length == 0)\n                    throw new ArgumentException(SR.UnsupportedHashAlgorithm, nameof(value));\n\n                _hashAlgorithmString = value;\n            }\n        }\n\n        /// <summary>\n        /// How to embed certificates when Signing\n        /// </summary>\n        /// <value></value>\n        public CertificateEmbeddingOption CertificateOption\n        {\n            get\n            {\n                return _certificateEmbeddingOption;\n            }\n            set\n            {\n                if ((value < CertificateEmbeddingOption.InCertificatePart) || (value > CertificateEmbeddingOption.NotEmbedded))","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs#L186-L222","documentation":"PackageDigitalSignatureManager.HashAlgorithm setter rejects a hash algorithm string it cannot use. After null-checking, the setter throws ArgumentException (SR.UnsupportedHashAlgorithm) when the assigned string is empty; WPF maps only a fixed set of XML-DSig algorithm URIs to underlying implementations, so anything outside that set is unsupported.","triggerScenarios":"Assigning an empty string (\"\") to PackageDigitalSignatureManager.HashAlgorithm, or assigning a string that is not one of the recognized XML digital signature algorithm URIs (e.g. XmlDsigSHA256Url etc.).","commonSituations":"Copy-pasting algorithm names like 'SHA256' or 'sha-256' instead of the full XML-DSig URI (http://www.w3.org/2001/04/xmlenc#sha256); building the string dynamically and producing \"\"; targeting FIPS/NIST variants whose URI strings differ.","solutions":["Assign a full XML-DSig algorithm URI such as SignedXml.XmlDsigSHA256Url instead of a friendly name","Verify the string is non-empty before assignment","Use the System.Security.Cryptography.Xml.SignedXml algorithm URL constants to guarantee exact spelling","Wrap the assignment in a try/catch when the algorithm string comes from external configuration"],"exampleFix":"// before\nmanager.HashAlgorithm = \"SHA256\"; // or manager.HashAlgorithm = algoNameFromConfig; // may be empty\n// after\nif (!string.IsNullOrEmpty(algoNameFromConfig))\n    manager.HashAlgorithm = algoNameFromConfig; // must be a valid XmlDsig URI\nelse\n    manager.HashAlgorithm = SignedXml.XmlDsigSHA256Url;","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(algoString) || !algoString.StartsWith(\"http://www.w3.org/\"))\n    throw new ArgumentException(\"HashAlgorithm must be a non-empty XML-DSig algorithm URI.\");","typeGuard":"bool IsValidHashAlgorithm(string s) => !string.IsNullOrEmpty(s) && s.StartsWith(\"http://\");","tryCatchPattern":"try { manager.HashAlgorithm = value; }\ncatch (ArgumentException ex) { log.Error(\"Unsupported hash algorithm\", ex); manager.HashAlgorithm = SignedXml.XmlDsigSHA256Url; }","preventionTips":["Always use SignedXml algorithm URL constants instead of hand-written strings","Null/empty-check any algorithm string sourced from config or user input","Document in your API that only XmlDSig URIs are accepted"],"tags":["wpf","packaging","argumentexception","hash-algorithm"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}