For quite some time, I search an alternative for “System.Security.Cryptography.Pkcs” on a Windows Mobile application developed with C# and DotNetFramework 3.5. In fact, I want sign and encrypt a XML file. I’ve already realized this operation on a desktop application:
X509Certificate2 cert = myCert;
// create ContentInfo (what is signed)
String msg = System.IO.File.ReadAllText(xmlPath);
byte[] msgBytes = Encoding.UTF8.GetBytes(msg);
ContentInfo content = new ContentInfo(msgBytes);
// object representing a signed message
SignedCms signedMessage = new SignedCms(content);
CmsSigner signer = new CmsSigner(cert);
signer.DigestAlgorithm = new Oid("SHA1");
signer.IncludeOption = X509IncludeOption.EndCertOnly;
// sign the message
signedMessage.ComputeSignature(signer, false);
byte[] cmsMessage = signedMessage.Encode();
// Encrypt message
X509Certificate2 certificatePK = new X509Certificate2(File.ReadAllBytes(publicKeyPDAPath));
ContentInfo contentSm = new ContentInfo(cmsMessage);
EnvelopedCms envelopedCms = new EnvelopedCms(contentSm);
CmsRecipient recipient = new CmsRecipient(SubjectIdentifierType.SubjectKeyIdentifier, certificatePK);
envelopedCms.Encrypt(recipient);
byte[] encryptedBytes = envelopedCms.Encode();
string str = System.Text.Encoding.Default.GetString(encryptedBytes);
How can I adapt this code for WinCE? Does it have an alternative for Windows Mobile?
Thank you for your help!