0

这是我的代码

static void Main(string[] args)
    {
        try
        {
            ContentInfo contentInfo = new ContentInfo(File.ReadAllBytes(@"D:\prj\temp\manifest.json"));
            SignedCms signedCms = new SignedCms(SubjectIdentifierType.IssuerAndSerialNumber, contentInfo);
            var signer = new CmsSigner(new X509Certificate2(@"D:\prj\temp\Shooger_Passbook_withoutKey.p12", "xxxxxxxxx"));
            signer.Certificates.Add(new X509Certificate2(@"D:\prj\temp\AppleIncRootCertificate.cer"));
            signer.Certificates.Add(new X509Certificate2(@"D:\prj\temp\AppleWWDRCA.cer"));
            signer.IncludeOption = X509IncludeOption.WholeChain;
            signer.SignedAttributes.Add(new Pkcs9SigningTime());
            signedCms.ComputeSignature(signer, false);

            byte[] myCmsMessage = signedCms.Encode();
            File.WriteAllBytes(@"D:\prj\temp\signature", myCmsMessage);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }

有人能告诉我为什么它会抛出“发生内部证书链接错误。”吗?

4

3 回答 3

1

For those tearing their hair out after renewing their certificate and finding it doesn't work, you now need to add the 'signed-time' attribute to the signature. Hence:

var oid = new Oid("1.2.840.113549.1.7.2");
ContentInfo contentInfo = new ContentInfo(oid, manifest);

var signedCms = new SignedCms(contentInfo, true);
var signer = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, myX509certificate);
signer.IncludeOption = X509IncludeOption.EndCertOnly;
signer.Certificates.Add(appleWwdrCertificate);

// new requirement to add 'signing-date'
signer.SignedAttributes.Add(new Pkcs9SigningTime(DateTime.Now));
signedCms.ComputeSignature(signer);

bytes[] signature = signedCms.Encode();
于 2013-09-25T10:32:17.670 回答
0

我已经为 .Net 创建了一个 OSS 库,可以为您处理所有这些。您只需要您自己的 Passbook 证书和主要的 Apple 证书。

https://github.com/tomasmcguinness/dotnet-passbook

于 2013-09-22T10:31:44.530 回答
0

尝试从 Windows 证书存储加载证书,

下面的链接将为您提供在 .net 中签名通行证的详细教程

http://geekswithblogs.net/MobileLOB/archive/2012/07/30/part-3ndashpassbook-server.aspx

希望这可以帮助.. :)

于 2012-12-24T12:43:26.943 回答