I'm trying to use an OpenSSL code in my .Net program. Here's the code:
openssl pkcs12 -in "My PassKit Cert.p12" -clcerts -nokeys -out certificate.pem
openssl pkcs12 -in "My PassKit Cert.p12" -nocerts -out key.pem
smime -binary -sign -signer certificate.pem -inkey key.pem -in manifest.json -out signature -outform DER
I tried to use .Net OpenSSL, but I absolutely have no idea how to use it, and I couldn't find a good documentation for it. I decided to use .Net to perform the same sign process, here's the code:
var dataToSign = System.IO.File.ReadAllBytes(filePathToSign);
ContentInfo contentInfo = new ContentInfo(dataToSign);
X509Certificate2 signerCert = new X509Certificate2(System.IO.File.ReadAllBytes(signerPfxCertPath), signerPfxCertPassword);
var signedCms = new SignedCms(contentInfo, true);
var signer = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, signerCert);
signer.IncludeOption = X509IncludeOption.EndCertOnly;
signedCms.ComputeSignature(signer);
var myCmsMessage = signedCms.Encode();
var buf = Encoding.Convert(Encoding.UTF7, Encoding.UTF8, myCmsMessage);
return Encoding.UTF8.GetString(buf, 0, buf.Length);
But the results between C# and OpenSSL are not the same. Can someone please help me out?
Thanks in advance!