當前位置: 首頁>>代碼示例>>C#>>正文


C# AlgorithmIdentifier.GetEncoded方法代碼示例

本文整理匯總了C#中Org.BouncyCastle.Asn1.X509.AlgorithmIdentifier.GetEncoded方法的典型用法代碼示例。如果您正苦於以下問題:C# AlgorithmIdentifier.GetEncoded方法的具體用法?C# AlgorithmIdentifier.GetEncoded怎麽用?C# AlgorithmIdentifier.GetEncoded使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Org.BouncyCastle.Asn1.X509.AlgorithmIdentifier的用法示例。


在下文中一共展示了AlgorithmIdentifier.GetEncoded方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Open

        protected Stream Open(
            Stream					outStream,
            string					encryptionOid,
            KeyParameter			encKey,
			Asn1Encodable			asn1Params,
			Asn1EncodableVector		recipientInfos)
        {
            Asn1Object asn1Object;
            ICipherParameters cipherParameters;

            if (asn1Params != null)
            {
                asn1Object = asn1Params.ToAsn1Object();
                cipherParameters = ParameterUtilities.GetCipherParameters(
                    encryptionOid, encKey, asn1Object);
            }
            else
            {
                asn1Object = DerNull.Instance;
                cipherParameters = encKey;
            }

            try
            {
                AlgorithmIdentifier encAlgId = new AlgorithmIdentifier(
                    new DerObjectIdentifier(encryptionOid),
                    asn1Object);

                //
                // ContentInfo
                //
                BerSequenceGenerator cGen = new BerSequenceGenerator(outStream);

                cGen.AddObject(CmsObjectIdentifiers.EnvelopedData);

                //
                // Encrypted Data
                //
                BerSequenceGenerator envGen = new BerSequenceGenerator(
                    cGen.GetRawOutputStream(), 0, true);

                envGen.AddObject(this.Version);

                DerSet derSet = _berEncodeRecipientSet
                    ?	new BerSet(recipientInfos)
                    :	new DerSet(recipientInfos);

                byte[] derSetEncoding = derSet.GetEncoded();

                envGen.GetRawOutputStream().Write(derSetEncoding, 0, derSetEncoding.Length);

                IBufferedCipher cipher = CipherUtilities.GetCipher(encryptionOid);

                cipher.Init(true, cipherParameters);

                BerSequenceGenerator eiGen = new BerSequenceGenerator(
                    envGen.GetRawOutputStream());

                eiGen.AddObject(PkcsObjectIdentifiers.Data);

                byte[] tmp = encAlgId.GetEncoded();
                eiGen.GetRawOutputStream().Write(tmp, 0, tmp.Length);

                BerOctetStringGenerator octGen = new BerOctetStringGenerator(
                    eiGen.GetRawOutputStream(), 0, false);

                Stream octetOutputStream = _bufferSize != 0
                    ?	octGen.GetOctetOutputStream(new byte[_bufferSize])
                    :	octGen.GetOctetOutputStream();

                CipherStream cOut = new CipherStream(octetOutputStream, null, cipher);

                return new CmsEnvelopedDataOutputStream(cOut, cGen, envGen, eiGen);
            }
            catch (SecurityUtilityException e)
            {
                throw new CmsException("couldn't create cipher.", e);
            }
            catch (InvalidKeyException e)
            {
                throw new CmsException("key invalid in message.", e);
            }
            catch (IOException e)
            {
                throw new CmsException("exception decoding algorithm parameters.", e);
            }
        }
開發者ID:hjgode,項目名稱:iTextSharpCF,代碼行數:87,代碼來源:CMSEnvelopedDataStreamGenerator.cs


注:本文中的Org.BouncyCastle.Asn1.X509.AlgorithmIdentifier.GetEncoded方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。