I have a XMLDocument that was signed with edcsa-sha384, out of the box .NET SignedXml does not support that algorithm, so I followed this article (https://www.scottbrady91.com/c-sharp/ecdsa-xml-dotnet) and called AddAlgorithm at the beginning of the program:
CryptoConfig.AddAlgorithm(typeof(Ecdsa384SignatureDescription),
"http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384");
Before AddAlgorithm, SignedXml was able to CheckSignature just fine for rsa-sha256, it was able to go through the XMLDocument and perform the signature check without throwing any errors...
After AddAlgorithm, it throws an error on the very second line of the xml file... Does anyone know what else I am missing to get ECDsa-RSA-384 to work?
InvalidOperationException
> There is an error in the XML document.
> <MySpecialDoc xmlns='https://www.hello.com/world/1.0'> was not expected.
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
The XML starts with something like this:
<?xml version="1.0"?>
<MySpecialDoc xmlns='https://www.hello.com/world/1.0' id="9baedc57-c4ef-41f5-8bdf-33fb14af3f71">
...
If you know an article on how to register custom algorithm, please share it. Thanks!
Ok, I've figured out the root cause of my error, it has nothing to do with how I
AddAlgorithm, it was actually working perfectly. The error I was seeing was due to the namespace in my XmlDocument being different. I generated some C# object class which had the namespace coded against1.1and the XML I was reading was an older1.0!!!!I spent a lot of time researching and getting ECDsa algorithm to work with
SignedXml, there actually isn't that much information out there regarding this, so hopefully this answer will be able to help someone else.To add unsupported algorithm to
SignedXml, you must first create aSignatureDescriptionclass, then register forSignedXmlto use viaCryptoConfig.AddAlgorithm.This is an example of
SignatureDescriptionfor ECDsa P-384, tested in .NET 8 at the time of typing this. Code forEcdsa384SignatureDescription.cs(you may wrap it around theSystem.Security.Cryptographynamespace, but not sure if that would clash if .NET actually provide the implementation):Once you've created the class, you need to register it somewhere in your program, to do so:
You should be able to sign and verify signature with ECDsa P-384 now.