I want to sign the hash value in ComputeSignature in XadesSignedXml in FirmaXadesNet.Core (https://github.com/ctt-gob-es/FirmaXadesNet) using pkcs11interop. Although everything seems correct, the signature value generated with pkcs11interop is incorrect.
Both methods use Sha256WithRsa. Why does wrong signaturevalue occur in Pkcs11interop?
public new void ComputeSignature(IObjectHandle privateKey, ISession session, IMechanism mechanism)
{
this.BuildDigestedReferences();
AsymmetricAlgorithm signingKey = this.SigningKey;
if (signingKey == null)
{
throw new CryptographicException("Cryptography_Xml_LoadKeyFailed");
}
if (this.SignedInfo.SignatureMethod == null)
{
if (!(signingKey is DSA))
{
if (!(signingKey is RSA))
{
throw new CryptographicException("Cryptography_Xml_CreatedKeyFailed");
}
if (this.SignedInfo.SignatureMethod == null)
{
this.SignedInfo.SignatureMethod = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
}
}
else
{
this.SignedInfo.SignatureMethod = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
}
}
SignatureDescription description = GetSignatureDescription();
if (description == null)
{
throw new CryptographicException("Cryptography_Xml_SignatureDescriptionNotCreated");
}
HashAlgorithm hash = description.CreateDigest();
if (hash == null)
{
throw new CryptographicException("Cryptography_Xml_CreateHashAlgorithmFailed");
}
//this.GetC14NDigest(hash);
byte[] hashValue = this.GetC14NDigest(hash, "ds");
//>>>> Instead <<<<<
//this.m_signature.SignatureValue = description.CreateFormatter(signingKey).CreateSignature(hash);
//>>>> This code<<<<<
this.m_signature.SignatureValue = session.Sign(mechanism, privateKey, hash.Hash);
}