コード例 #1
0
ファイル: AnchorBundle.cs プロジェクト: blinds52/nhind
        /// <summary>
        /// Parse raw bundle data into a CMS structure
        /// </summary>
        /// <param name="bundleData">Array of bytes</param>
        /// <param name="checkSignatureOnly">If bundle is signed, check signature but don't verify signature cert chain</param>
        /// <returns>The parsed Cms structure</returns>
        public static SignedCms ParseCms(byte[] bundleData, bool checkSignatureOnly)
        {
            if (bundleData.IsNullOrEmpty())
            {
                throw new ArgumentNullException("bundleData");
            }

            SignedCms cms = null;

            try
            {
                cms = DecodeDerBundle(bundleData);
            }
            catch
            {
            }
            if (cms == null)
            {
                cms = DecodePEMBundle(bundleData);
            }

            if (!cms.HasSignatures())
            {
                // No signature. Must assume is already p7b
                return(cms);
            }

            cms.CheckSignature(checkSignatureOnly);
            if (!cms.HasContent())
            {
                return(null);
            }

            SignedCms p7bCms = new SignedCms();

            p7bCms.Decode(cms.ContentInfo.Content);
            return(p7bCms);
        }