2012-10-13 41 views
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()); 
     } 
    } 

有人能告訴我爲什麼它會拋出「內部證書鏈出錯。」?

回答

1

對於那些撕扯自己的頭髮,更新他們的證書,並發現它不工作後,你現在需要添加「簽署時」屬性的簽名。因此:

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();