0 votes
by (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?
Thanks

1 Answer

0 votes
by (72.7k 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.

...