iTextSharp中的数字签名

时间:2015-07-28 10:37:20

标签: c# digital-certificate

以下代码用于从pdf创建.ts文件。它使用时间戳的Web服务。 Class DigitalSignature {

    public void OpenPdf(string path)
    {


        try
        {

            byte[] bytData = File.ReadAllBytes(path);
            SHA256Managed sha = new SHA256Managed();
            byte[] hash = sha.ComputeHash(bytData);
            mk.kibs.wstsatest.wsTSATest oWS = new mk.kibs.wstsatest.wsTSATest();

            //  X509Store Store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            var Store = new X509Store(StoreLocation.CurrentUser);
            Store.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection Col = Store.Certificates.Find(X509FindType.FindByIssuerName, "KIBS", true);
            oWS.Url = Settings.Default.DigitalSignature_mk_kibs_wstsatest_wsTSATest;
            if (Col.Count > 0)
            {

                oWS.ClientCertificates.Add(Col[0]);
            }

                mk.kibs.wstsatest.TSResponse_Bytes resp = oWS.funGenerateTS_Bytes(hash);
                string strFailureInfo = resp.strFailureInfo;
                byte[] byTimeStamped = resp.bytTSToken;
                oWS.Dispose();
                if (strFailureInfo == string.Empty)
                {
                    File.WriteAllBytes(path +".ts"+ byTimeStamped);

                }
                else
                {
                    MessageBox.Show(strFailureInfo);
                }
            }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);

        }          

    }

我成功使用上面的代码从pdf文件生成.ts。任何建议如何从ts生成数字签名文件。 ?

0 个答案:

没有答案