Subject: Signing SAML2 Response with SHA-256
Date: 2016-05-06 17:29:45
From: Benjamin Loving
Source: signing-saml2-response-sha-256
----------------------------------------------------------------------

Hello. Thanks for producing the Ultimate SAML product. It has been helpful so far. I'm trying to sign a ComponentPro.Saml2.Response using SHA-256. I followed the instructions given on the website here and receive the exception below the code snippet. Are the digestMethod and signatureMethod correct when calling Sign method? Is more setup needed? 

Sincerely,

Ben

[code lang='c#']

...
using System.Deployment.Internal.CodeSigning;
using System.IdentityModel.Tokens;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
...
 
public void GetResponse(string nameId) {  
var samlResponse = new ComponentPro.Saml2.Response();
...
  CryptoConfig.AddAlgorithm(typeof(RSAPKCS1SHA256SignatureDescription), "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");
 
   samlResponse.Sign(signingCertificate, "http://www.w3.org/2001/04/xmlenc#sha256", "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");

...

return response;

}

[/code]

 

Exception.InnerException.Message: Invalid algorithm specified.

[code lang='c#']StackTrace "
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.Utils.SignValue(SafeKeyHandle hKey, Int32 keyNumber, Int32 calgKey, Int32 calgHash, Byte[] hash, Int32 cbHash, ObjectHandleOnStack retSignature)
at System.Security.Cryptography.Utils.SignValue(SafeKeyHandle hKey, Int32 keyNumber, Int32 calgKey, Int32 calgHash, Byte[] hash)
at System.Security.Cryptography.RSACryptoServiceProvider.SignHash(Byte[] rgbHash, Int32 calgHash)
at System.Security.Cryptography.RSAPKCS1SignatureFormatter.CreateSignature(Byte[] rgbHash)
at System.Security.Cryptography.AsymmetricSignatureFormatter.CreateSignature(HashAlgorithm hash)
at System.Security.Cryptography.Xml.SignedXml.ComputeSignature()
at ComponentPro.Saml.SamlUtil.ComputeSignature(XmlElement xmlElement, String elementId, AsymmetricAlgorithm signingKey, KeyInfo keyInfo, SignedXml signedXml, String inclusiveNamespacesPrefixList, String digestMethod, String signatureMethod)" string [/code]
 

 

---------------------------------------------------------------------- Note: This question has been asked on the Q&A forum of Thang Dang's fraudulent ComponentPro brand If you purchased anything from ComponentPro, you have been scammed. Contact the payment processor who sold you the license and ask for your money back. Back to ComponentPro Q&A Forum Index