Ejemplo n.º 1
0
        /// <summary>5.3.2 使用证书进行PKCS7签名 2011-12-19
        ///
        /// </summary>
        /// <param name="sSource"></param>
        /// <param name="isNotHasSource"></param>
        /// <param name="pwd"></param>
        /// <param name="oCert"></param>
        /// <returns></returns>
        public static String signPKCS7ByCertificate(String sSource, Boolean isNotHasSource, String pwd, SecuInter.X509Certificate oCert)
        {
            SecuInter.Signer     oSigner     = new SecuInter.Signer();
            SecuInter.SignedData oSignedData = new SecuInter.SignedData();
            SecuInter.Utilities  oUtil       = new SecuInter.Utilities();
            if (sSource == "")
            {
                throw new Exception("原文内容为空!");
            }


            oSigner.Certificate   = oCert;
            oSigner.HashAlgorithm = SECUINTER_HASH_ALGORITHM.SECUINTER_SHA1_ALGORITHM;
            oSigner.UseSigningCertificateAttribute = false;
            oSigner.UseSigningTime = false;
            if (!String.IsNullOrEmpty(pwd))
            {
                bool ok = oSigner.SetUserPIN(pwd);
                if (!ok)
                {
                    throw new Exception("密码有误!");
                }
            }
            oSignedData.Content  = sSource;
            oSignedData.Detached = isNotHasSource;

            object arrRT = oSignedData.Sign(oSigner, SECUINTER_CMS_ENCODE_TYPE.SECUINTER_CMS_ENCODE_BASE64);

            oSignedData = null;
            oSigner     = null;
            return(arrRT.ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// PKCS#7时间戳签名
        /// </summary>
        /// <param name="bContent">签名内容</param>
        /// <param name="tsaUrl">时间戳服务器URL</param>
        /// <param name="IsNotHasSource"></param>
        /// <returns>签名值</returns>
        public static String signPKCS7WithTSA(String bContent, String tsaUrl, Boolean IsNotHasSource)
        {
            if (bContent == "")
            {
                throw new Exception("原文内容为空!");
            }
            if (tsaUrl == "")
            {
                throw new Exception("时间戳URL为空!");
            }

            SecuInter.X509Certificate oCert = getX509Certificate(SECUINTER_CURRENT_USER_STORE, SECUINTER_MY_STORE, SECUINTER_CERTTYPE_SIGN, SECUINTER_NETCA_OTHER);
            if (oCert == null)
            {
                throw new Exception("未选择证书!");
            }

            SecuInter.Signer          oSigner          = new SecuInter.Signer();
            SecuInter.SignedData      oSignedData      = new SecuInter.SignedData();
            SecuInter.X509Certificate oX509Certificate = new SecuInter.X509Certificate();
            //oX509Certificate = oCert;
            oSigner.Certificate   = oCert;
            oSigner.HashAlgorithm = SecuInter.SECUINTER_HASH_ALGORITHM.SECUINTER_SHA1_ALGORITHM;
            oSigner.UseSigningCertificateAttribute = false;
            oSigner.UseSigningTime = true;
            oSignedData.Content    = bContent;
            oSignedData.Detached   = IsNotHasSource;

            Object arrRT = oSignedData.SignWithTSATimeStamp(oSigner, tsaUrl, "", oX509Certificate, SECUINTER_CMS_ENCODE_TYPE.SECUINTER_CMS_ENCODE_BASE64);

            oSignedData      = null;
            oSigner          = null;
            oCert            = null;
            oX509Certificate = null;
            return(arrRT.ToString());
        }