Malformed Reference Element

前端 未结 1 1419
灰色年华
灰色年华 2020-12-11 18:12

I am attempting to add References to my Security Header and am running into a fairly generic error:

Malformed Reference Element

<
相关标签:
1条回答
  • 2020-12-11 18:49

    It looks like, at least for the time being, the answer to getting this working is as follows.

    Instead of using the SignedXml class, create a new SignedXmlWithId object, using the class detailed here.

    // Create a new XML Document.
    XmlDocument xdoc = new XmlDocument();
    
    xdoc.PreserveWhitespace = true;
    
    // Load the passed XML File using its name.
    xdoc.Load(new XmlTextReader(fileName));
    
    // Create a SignedXml Object.
    //SignedXml xSigned = new SignedXml(xdoc);
    SignedXmlWithId xSigned = new SignedXmlWithId(xdoc); // Use this class instead of the SignedXml class above.
    
    // Add the key to the SignedXml document.
    xSigned.SigningKey = cert.PrivateKey;
    xSigned.Signature.Id = SignatureID;
    xSigned.SignedInfo.CanonicalizationMethod = 
            SignedXml.XmlDsigExcC14NWithCommentsTransformUrl;
    
    //Initialize a variable to contain the ID of the Timestamp element.
    string elementId = TimestampID;
    
    Reference reference = new Reference()
    {
        Uri = "#" + elementId
    };
    
    XmlDsigExcC14NTransform env = new XmlDsigExcC14NTransform();
    env.InclusiveNamespacesPrefixList = _includedPrefixList;
    reference.AddTransform(env);
    
    xSigned.AddReference(reference);
    
    // Add Key Information (omitted)
    
    // Compute Signature
    xSigned.ComputeSignature();
    
    0 讨论(0)
提交回复
热议问题