Is possible to do the Xml signature with the new version

0 votes
asked Jun 8 by ruggero.bandera (120 points)

I need to create XML signature file with compactFramework (as xmlsec does using C language and openSSL).
Is it possible with you library do this operation?

1 Answer

0 votes
answered Jun 8 by Lukas Matyska (37,860 points)

Yes, it is possible to create signatures on .NET CF.

The code looks like this:

// load certificate with private key
var cert = Certificate.LoadPfx(certPath, certPassword);

// set desired parameters
var parameters = new SignatureParameters()
    HashAlgorithm = HashingAlgorithmId.SHA256,
    Format = SignatureFormat.Pkcs,

// compute signature
byte[] signedData = cert.SignMessage(dataToSign, parameters);

// convert binary data to base-64 string
string signature = Convert.ToBase64String(signedData);

However, you are responsible to provide dataToSign for the SignMessage method.

What I know about XML signatures, there is typically specified: normalization for XML, signature format, hash method, etc.