C# 生成存折通行证签名文件

use*_*183 1 c# passbook

  1. App是通过C#生成通行证(Iphone中的Passbook App)。
  2. 我已经下载了Pass证书和AppleWWDRCA证书。
  3. 为了生成 pass,我可以生成 pass.json 和 manifest.json。
  4. 但是,当我使用签名证书和 manifest.json 生成 PKCS 7 分离签名文件时,iPhone 中的 Passbook 应用程序无法识别它。
  5. 我在 MAC 中使用 openssl 生成了分离的签名文件,该文件工作正常并安装在 Passbook 中。
  6. 我已经下载了pass证书和AppleWWDRCA证书
  7. 任何人都可以帮助我一步步在 C# 中创建签名文件的过程以及要使用的方法

我已将两个证书存储在本地文件夹中,而不是 Windows 本地存储中。我之前曾在 Windows 本地商店中尝试过,但没有成功。

以下是用于签名的方法,

 X509Certificate2 card = GetCertificate(); //Fetches the pass certificate   
X509Certificate2 appleCA = GetAppleCertificate();  //Fetches the AppleWWDRCA certificate    
    byte[] manifestbytes = Encoding.ASCII.GetBytes(manifest);
            ContentInfo contentinfo = new ContentInfo(manifestbytes);
            SignedCms signedCms = new SignedCms(contentinfo, true);
            var signer = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber,card);
            signer.Certificates.Add(new X509Certificate2(appleCA));
            signer.IncludeOption = X509IncludeOption.WholeChain;
            signer.SignedAttributes.Add(new Pkcs9SigningTime());
            signedCms.ComputeSignature(signer);
            signatureFile = signedCms.Encode();
            return signatureFile;
Run Code Online (Sandbox Code Playgroud)

Tom*_*ess 5

我创建了一个开源 C# 库来生成这些通道。

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

这是我用来执行文件签名的代码(它使用 BouncyCastle)

// Load your pass type identifier certificate
X509Certificate2 card = GetCertificate(request);

Org.BouncyCastle.X509.X509Certificate cert = DotNetUtilities.FromX509Certificate(card);
Org.BouncyCastle.Crypto.AsymmetricKeyParameter privateKey = DotNetUtilities.GetKeyPair(card.PrivateKey).Private;

// Load the Apple certificate
X509Certificate2 appleCA = GetAppleCertificate(request);
X509.X509Certificate appleCert = DotNetUtilities.FromX509Certificate(appleCA);


ArrayList intermediateCerts = new ArrayList();

intermediateCerts.Add(appleCert);
intermediateCerts.Add(cert);

Org.BouncyCastle.X509.Store.X509CollectionStoreParameters PP = new Org.BouncyCastle.X509.Store.X509CollectionStoreParameters(intermediateCerts);
Org.BouncyCastle.X509.Store.IX509Store st1 = Org.BouncyCastle.X509.Store.X509StoreFactory.Create("CERTIFICATE/COLLECTION", PP);

CmsSignedDataGenerator generator = new CmsSignedDataGenerator();

generator.AddSigner(privateKey, cert, CmsSignedDataGenerator.DigestSha1);
generator.AddCertificates(st1);

CmsProcessable content = new CmsProcessableByteArray(manifestFile);
CmsSignedData signedData = generator.Generate(content, false);

signatureFile = signedData.GetEncoded();
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助。