当前位置: 首页>>代码示例>>C#>>正文


C# Document.OpenStream方法代码示例

本文整理汇总了C#中Document.OpenStream方法的典型用法代码示例。如果您正苦于以下问题:C# Document.OpenStream方法的具体用法?C# Document.OpenStream怎么用?C# Document.OpenStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Document的用法示例。


在下文中一共展示了Document.OpenStream方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExtendSignatures

		/// <exception cref="System.IO.IOException"></exception>
		public virtual Document ExtendSignatures(Document document, Document originalData
			, SignatureParameters parameters)
		{
			try
			{
				CmsSignedData signedData = new CmsSignedData(document.OpenStream());
				SignerInformationStore signerStore = signedData.GetSignerInfos();
				AList<SignerInformation> siArray = new AList<SignerInformation>();				

                foreach (SignerInformation si in signerStore.GetSigners())
                {                    
                    try
                    {
                        //jbonilla - Hack para evitar errores cuando una firma ya ha sido extendida.
                        //Se asume que sólo se extiende las firmas desde BES.
                        //TODO jbonilla - Se debería validar hasta qué punto se extendió (BES, T, C, X, XL).
                        if(si.UnsignedAttributes.Count == 0)
                        {
                            siArray.AddItem(ExtendCMSSignature(signedData, si, parameters, originalData));
                        }
                        else
                        {
                            LOG.Error("Already extended?");
                            siArray.AddItem(si);
                        }                        
                    }
                    catch (IOException)
                    {
                        LOG.Error("Exception when extending signature");
                        siArray.AddItem(si);
                    }
                }
				
				SignerInformationStore newSignerStore = new SignerInformationStore(siArray);
				CmsSignedData extended = CmsSignedData.ReplaceSigners(signedData, newSignerStore);
				return new InMemoryDocument(extended.GetEncoded());
			}
			catch (CmsException)
			{
				throw new IOException("Cannot parse CMS data");
			}
		}
开发者ID:Gianluigi,项目名称:dssnet,代码行数:43,代码来源:CAdESSignatureExtension.cs

示例2: ExtendSignatures

 /// <exception cref="System.IO.IOException"></exception>
 public virtual Document ExtendSignatures(Document document, Document originalData
     , SignatureParameters parameters)
 {
     InputStream input = document.OpenStream();
     if (this.tspSource == null)
     {
         throw new ConfigurationException(ConfigurationException.MSG.CONFIGURE_TSP_SERVER);
     }
     try
     {
         throw new NotImplementedException();
     }
     finally
     {
         if (input != null)
         {
             input.Close();
         }
     }
 }
开发者ID:Gianluigi,项目名称:dssnet,代码行数:21,代码来源:XAdESProfileT.cs

示例3: ExtendSignature

        /// <exception cref="System.IO.IOException"></exception>
        public virtual Document ExtendSignature(object signatureId, Document document, Document
             originalData, SignatureParameters parameters)
        {
            if (this.tspSource == null)
            {
                throw new ConfigurationException(ConfigurationException.MSG.CONFIGURE_TSP_SERVER);
            }

            XmlDocument envelopedSignatureXmlDocument;
            XmlDocument xadesDocument;
            XmlElement signature;            
            XadesSignedXml xadesSignedXml;

            xadesDocument = XmlUtils.ToXmlDocument(document);
            xadesDocument.PreserveWhitespace = true;
            xadesDocument.Load(document.OpenStream());

            xadesSignedXml = new XadesSignedXml(xadesDocument.DocumentElement); //Needed if it is a enveloped signature document

            signature = xadesSignedXml.GetIdElement(xadesDocument, (string)signatureId);
            
            xadesSignedXml.LoadXml(signature);

            ExtendSignatureTag(xadesSignedXml);

            envelopedSignatureXmlDocument = XmlUtils.ToXmlDocument(originalData);
            return XmlUtils.ToDocument(envelopedSignatureXmlDocument, xadesSignedXml);
        }
开发者ID:Gianluigi,项目名称:dssnet,代码行数:29,代码来源:XAdESProfileT.cs

示例4: ExtendSignature

		/// <exception cref="System.IO.IOException"></exception>
		public virtual Document ExtendSignature(object signatureId, Document document, Document
			 originalData, SignatureParameters parameters)
		{
			SignerID toExtendId = (SignerID)signatureId;
			try
			{
				CmsSignedData signedData = new CmsSignedData(document.OpenStream());
				SignerInformationStore signerStore = signedData.GetSignerInfos();
				AList<SignerInformation> siArray = new AList<SignerInformation>();
				//Iterator<object> infos = signerStore.GetSigners().Iterator();
                IEnumerator infos = signerStore.GetSigners().GetEnumerator();
				while (infos.MoveNext())
				{
					SignerInformation si = (SignerInformation)infos.Current;
					if (si.SignerID.Equals(toExtendId))
					{
						try
						{
							siArray.AddItem(ExtendCMSSignature(signedData, si, parameters, originalData));
						}
						catch (IOException)
						{
							LOG.Error("Exception when extending signature");
							siArray.AddItem(si);
						}
					}
				}
				SignerInformationStore newSignerStore = new SignerInformationStore(siArray);
				CmsSignedData extended = CmsSignedData.ReplaceSigners(signedData, newSignerStore);
				return new InMemoryDocument(extended.GetEncoded());
			}
			catch (CmsException)
			{
				throw new IOException("Cannot parse CMS data");
			}
		}
开发者ID:Gianluigi,项目名称:dssnet,代码行数:37,代码来源:CAdESSignatureExtension.cs

示例5: AddASignatureToDocument

        /// <summary>Add a signature to the already CMS signed data document.</summary>
        /// <remarks>Add a signature to the already CMS signed data document.</remarks>
        /// <param name="_signedDocument"></param>
        /// <param name="parameters"></param>
        /// <param name="signatureValue"></param>
        /// <returns></returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public virtual Document AddASignatureToDocument(Document _signedDocument, SignatureParameters
             parameters, byte[] signatureValue)
        {
            if (parameters.SignaturePackaging != SignaturePackaging.ENVELOPING)
            {
                throw new ArgumentException("Unsupported signature packaging " + parameters.SignaturePackaging);
            }
            try
            {
                CmsSignedData originalSignedData = null;
                using (var stream = _signedDocument.OpenStream())
                {
                    originalSignedData = new CmsSignedData(stream);
                }

                //jbonilla - No aplica para C#
                //string jsAlgorithm = parameters.GetSignatureAlgorithm().GetJavaSignatureAlgorithm
                //    (parameters.GetDigestAlgorithm());
                //PreComputedContentSigner cs = new PreComputedContentSigner(jsAlgorithm, signatureValue
                //    );
                PreComputedSigner s = new PreComputedSigner(signatureValue);
                //DigestCalculatorProvider digestCalculatorProvider = new BcDigestCalculatorProvider
                //    ();
                //CMSSignedDataGenerator generator = CreateCMSSignedDataGenerator(cs, digestCalculatorProvider
                //    , parameters, GetSigningProfile(parameters), true, originalSignedData);
                CmsSignedDataGenerator generator = CreateCMSSignedDataGenerator(s, parameters
                    , GetSigningProfile(parameters), true, originalSignedData);

                //if (originalSignedData == null || originalSignedData.SignedContent.GetContent
                //    () == null)                
                if (originalSignedData == null || originalSignedData.SignedContent == null)
                {
                    throw new RuntimeException("Cannot retrieve orignal content");
                }
                //byte[] octetString = (byte[])originalSignedData.SignedContent.GetContent();
                //CmsProcessableByteArray content = new CmsProcessableByteArray(octetString);
                CmsProcessable content = originalSignedData.SignedContent;
                CmsSignedData data = generator.Generate(content, true);
                Document signedDocument = new CMSSignedDocument(data);
                CAdESSignatureExtension extension = GetExtensionProfile(parameters);
                if (extension != null)
                {
                    signedDocument = extension.ExtendSignatures(new CMSSignedDocument(data), null, parameters);
                }
                return signedDocument;
            }
            catch (CmsException e)
            {
                throw new RuntimeException(e);
            }
        }
开发者ID:Gianluigi,项目名称:dssnet,代码行数:58,代码来源:CAdESService.cs

示例6: SignDocument

        /// <summary><inheritDoc></inheritDoc></summary>
        /// <exception cref="System.IO.IOException"></exception>
        public virtual Document SignDocument(Document document, SignatureParameters parameters
            , byte[] signatureValue)
        {
            if (parameters.SignaturePackaging != SignaturePackaging.ENVELOPING && parameters
                .SignaturePackaging != SignaturePackaging.DETACHED)
            {
                throw new ArgumentException("Unsupported signature packaging " + parameters.SignaturePackaging);
            }
            try
            {
                //jbonilla - No aplica para C#
                //string jsAlgorithm = parameters.GetSignatureAlgorithm().GetJavaSignatureAlgorithm
                //    (parameters.GetDigestAlgorithm());
                //PreComputedContentSigner cs = new PreComputedContentSigner(jsAlgorithm, signatureValue
                //    );
                PreComputedSigner s = new PreComputedSigner(signatureValue);

                //DigestCalculatorProvider digestCalculatorProvider = new BcDigestCalculatorProvider
                //    ();
                //CMSSignedDataGenerator generator = CreateCMSSignedDataGenerator(cs, digestCalculatorProvider
                //    , parameters, GetSigningProfile(parameters), true, null);
                CmsSignedDataGenerator generator = CreateCMSSignedDataGenerator(s, parameters
                    , GetSigningProfile(parameters), true, null);
                byte[] toBeSigned = Streams.ReadAll(document.OpenStream());
                CmsProcessableByteArray content = new CmsProcessableByteArray(toBeSigned);
                bool includeContent = true;
                if (parameters.SignaturePackaging == SignaturePackaging.DETACHED)
                {
                    includeContent = false;
                }
                CmsSignedData data = generator.Generate(content, includeContent);
                Document signedDocument = new CMSSignedDocument(data);
                CAdESSignatureExtension extension = GetExtensionProfile(parameters);
                if (extension != null)
                {
                    signedDocument = extension.ExtendSignatures(new CMSSignedDocument(data), document
                        , parameters);
                }
                return signedDocument;
            }
            catch (CmsException e)
            {
                throw new RuntimeException(e);
            }
        }
开发者ID:Gianluigi,项目名称:dssnet,代码行数:47,代码来源:CAdESService.cs

示例7: ToBeSigned

        /// <exception cref="System.IO.IOException"></exception>
        public virtual Stream ToBeSigned(Document document, SignatureParameters parameters
            )
        {
            if (parameters.SignaturePackaging != SignaturePackaging.ENVELOPING && parameters
                .SignaturePackaging != SignaturePackaging.DETACHED)
            {
                throw new ArgumentException("Unsupported signature packaging " + parameters.SignaturePackaging);
            }
            //jbonilla - No aplica para C#
            //SignatureInterceptorProvider provider = new SignatureInterceptorProvider();
            //Security.AddProvider(provider);
            //string jsAlgorithm = parameters.GetSignatureAlgorithm().GetJavaSignatureAlgorithm
            //    (parameters.GetDigestAlgorithm());
            //PreComputedContentSigner contentSigner = new PreComputedContentSigner(jsAlgorithm
            //    );
            PreComputedSigner signer = new PreComputedSigner();
            //CmsSignedDataGenerator generator = CreateCMSSignedDataGenerator(contentSigner, digestCalculatorProvider
            //    , parameters, GetSigningProfile(parameters), false, null);
            CmsSignedDataGenerator generator = CreateCMSSignedDataGenerator
                (signer, parameters, GetSigningProfile(parameters), false, null);

            byte[] toBeSigned = Streams.ReadAll(document.OpenStream());
            CmsProcessableByteArray content = new CmsProcessableByteArray(toBeSigned);
            try
            {
                bool includeContent = true;
                if (parameters.SignaturePackaging == SignaturePackaging.DETACHED)
                {
                    includeContent = false;
                }
                CmsSignedData signed = generator.Generate(content, includeContent);

                //jbonilla - El ISigner devuelve el mismo hash sin firmar para permitir
                //la generación de la firma por un medio externo, como un token.
                /*return new ByteArrayInputStream(contentSigner.GetByteOutputStream().ToByteArray());*/
                return new MemoryStream(signer.CurrentSignature());
            }
            catch (CmsException e)
            {
                throw new IOException("CmsException", e);
            }
        }
开发者ID:Gianluigi,项目名称:dssnet,代码行数:43,代码来源:CAdESService.cs

示例8: CMSDocumentValidator

		/// <summary>The default constructor for PKCS7DocumentValidator.</summary>
		/// <remarks>The default constructor for PKCS7DocumentValidator.</remarks>
		/// <exception cref="System.IO.IOException"></exception>
		/// <exception cref="Org.Bouncycastle.Cms.CmsException"></exception>
		public CMSDocumentValidator(Document document)
		{
			this.Document = document;
			this.cmsSignedData = new CmsSignedData(document.OpenStream());
		}
开发者ID:Gianluigi,项目名称:dssnet,代码行数:9,代码来源:CMSDocumentValidator.cs

示例9: ToXmlDocument

        public static XmlDocument ToXmlDocument(Document document)
        {
            XmlDocument xmlDocument;
            xmlDocument = new XmlDocument();
            xmlDocument.PreserveWhitespace = true;
            xmlDocument.Load(document.OpenStream());

            return xmlDocument;
        }
开发者ID:Gianluigi,项目名称:dssnet,代码行数:9,代码来源:XMLUtils.cs


注:本文中的Document.OpenStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。