Generate Apple Passbook Coupon/S-MIME Signature in Visual Studio

我怕爱的太早我们不能终老 提交于 2019-12-08 01:06:46

问题


I am trying to create a Apple wallet passes in my system, after reading Different S/MIME signature between OpenSSL and C# and Apple Passbook coupons from C#, the system can create .pkasss automatically now.

And my problem is signature cannot create successfully in actual. If I using iPhone and try to open the .pkpass file, it can't be open!! I find out that is the problem is coming form signature, if I using mac to create a signature in terminal, it create a 3326bytes size signature; my code only can create a 3002 bytes file, which means the signature must be miss something.

Does Mac OS X method have a big difference between Windows OS method?

Has anyone faced this problem before? Does anyone know why the signatures are different?

Does anyone know how t fix it?


This is my source code:

var cert = new X509Certificate2(assetsFolder + p12File, p12Password);
var buffer = File.ReadAllBytes(Path.Combine(assetsFolder, "manifest.json"));

var cont = new ContentInfo(buffer);
var cms = new SignedCms(cont, true);
var signer = new CmsSigner(cert)
{
    IncludeOption = X509IncludeOption.ExcludeRoot,
    SignerIdentifierType = SubjectIdentifierType.IssuerAndSerialNumber, 
};
cms.ComputeSignature(signer, true);

var myCmsMessage = cms.Encode();
File.WriteAllBytes(Path.Combine(assetsFolder, "signature"), myCmsMessage);

Big Thanks!!!

----------------------------------UPDATE---------------------------------

I found the ans of signature!!! The setting of OID and SignerIdentifierType will affert the signature Here is my solution:

        byte[] buffer = File.ReadAllBytes(Path.Combine(assetsFolder, "manifest.json"));
        X509Certificate2 cert = new X509Certificate2(assetsFolder + p12File, p12Password);
        var oid = new Oid("1.2.840.113549.1.7.2");
        ContentInfo contentInfo = new ContentInfo(oid, buffer);
        SignedCms signedCms = new SignedCms(contentInfo, true); 
        var cmsSigner = new CmsSigner(cert);
        cmsSigner.IncludeOption = X509IncludeOption.ExcludeRoot;
        cmsSigner.SignedAttributes.Add(new Pkcs9SigningTime(DateTime.Now));
        cmsSigner.SignerIdentifierType = SubjectIdentifierType.SubjectKeyIdentifier;
        signedCms.ComputeSignature(cmsSigner);

        byte[] myCmsMessage = signedCms.Encode();
        return myCmsMessage;

来源:https://stackoverflow.com/questions/40296896/generate-apple-passbook-coupon-s-mime-signature-in-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!