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


C# Asn1.Asn1InputStream类代码示例

本文整理汇总了C#中Org.BouncyCastle.Asn1.Asn1InputStream的典型用法代码示例。如果您正苦于以下问题:C# Asn1InputStream类的具体用法?C# Asn1InputStream怎么用?C# Asn1InputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Asn1InputStream类属于Org.BouncyCastle.Asn1命名空间,在下文中一共展示了Asn1InputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Check

 public virtual bool Check(CertificateAndContext cert)
 {
     //TODO jbonilla - validar.
     //byte[] certificatePolicies = cert.GetCertificate().GetExtensionValue(X509Extensions.CertificatePolicies);
     Asn1OctetString certificatePolicies = cert.GetCertificate().GetExtensionValue(X509Extensions.CertificatePolicies);
     if (certificatePolicies != null)
     {
         try
         {
             //Asn1InputStream input = new Asn1InputStream(certificatePolicies);
             //DerOctetString s = (DerOctetString)input.ReadObject();
             DerOctetString s = (DerOctetString)certificatePolicies;
             byte[] content = s.GetOctets();
             Asn1InputStream input = new Asn1InputStream(content);
             DerSequence seq = (DerSequence)input.ReadObject();
             for (int i = 0; i < seq.Count; i++)
             {
                 PolicyInformation policyInfo = PolicyInformation.GetInstance(seq[i]);
                 if (policyInfo.PolicyIdentifier.Id.Equals(policyOid))
                 {
                     return true;
                 }
             }
         }
         catch (IOException e)
         {
             throw new RuntimeException(e);
         }
     }
     return false;
 }
开发者ID:Gianluigi,项目名称:dssnet,代码行数:31,代码来源:PolicyIdCondition.cs

示例2: Check

 public virtual bool Check(CertificateAndContext cert)
 {
     //TODO jbonilla - Validar
     //byte[] qcStatement = cert.GetCertificate().GetExtensionValue(X509Extensions.QCStatements);
     Asn1OctetString qcStatement = cert.GetCertificate().GetExtensionValue(X509Extensions.QCStatements);
     if (qcStatement != null)
     {
         try
         {
             //Asn1InputStream input = new Asn1InputStream(qcStatement);                    
             //DerOctetString s = (DerOctetString)input.ReadObject();
             DerOctetString s = (DerOctetString)qcStatement;
             byte[] content = s.GetOctets();
             Asn1InputStream input = new Asn1InputStream(content);
             DerSequence seq = (DerSequence)input.ReadObject();
             for (int i = 0; i < seq.Count; i++)
             {
                 QCStatement statement = QCStatement.GetInstance(seq[i]);
                 if (statement.StatementId.Id.Equals(qcStatementId))
                 {
                     return true;
                 }
             }
             return false;
         }
         catch (IOException e)
         {
             throw new RuntimeException(e);
         }
     }
     return false;
 }
开发者ID:Gianluigi,项目名称:dssnet,代码行数:32,代码来源:QcStatementCondition.cs

示例3: DecodeFromDer

        public static EcdsaSignature DecodeFromDer(byte[] bytes)
        {
            try
            {
                var decoder = new Asn1InputStream(bytes);
                var seq = (Asn1Sequence)decoder.ReadObject();
                DerInteger r, s;
                try
                {
                    r = (DerInteger)seq[0];
                    s = (DerInteger)seq[1];
                }
                catch (InvalidCastException)
                {
                    return null;
                }
                decoder.Close();

                // OpenSSL deviates from the DER spec by interpreting these values as unsigned, though they should not be
                // Thus, we always use the positive versions. See: http://r6.ca/blog/20111119T211504Z.html
                return new EcdsaSignature(r.PositiveValue, s.PositiveValue);
            }
            catch (IOException e)
            {
                throw new ApplicationException("Decoding form DER failed", e);
            }
        }
开发者ID:kueiwa,项目名称:ripple-cs,代码行数:27,代码来源:EcdsaSignature.cs

示例4: readTimeStampResp

		private static TimeStampResp readTimeStampResp(
			Asn1InputStream input)
		{
			try
			{
				return TimeStampResp.GetInstance(input.ReadObject());                
			}
			catch (ArgumentException e)
			{
				throw new TspException("malformed timestamp response: " + e, e);
			}
			catch (InvalidCastException e)
			{
				throw new TspException("malformed timestamp response: " + e, e);
			}
            catch (EndOfStreamException e)
            {
                //jbonilla - TSA del BCE por alguna razón devuelve "null\n"
                string resp = "";
                if (input.CanSeek && input.CanRead && input.Length > 0)
                {
                    input.Seek(0, SeekOrigin.Begin);
                    resp = Strings.FromByteArray(
                        Org.BouncyCastle.Utilities.IO.Streams.ReadAll(input));
                }                
                throw new TspException("malformed timestamp response: " 
                    + resp + " " + e.Message, e);
            }
		}
开发者ID:Gianluigi,项目名称:dssnet,代码行数:29,代码来源:TimeStampResponse.cs

示例5: GetAuthorityKeyFromCertificate

        public static string GetAuthorityKeyFromCertificate(X509Certificate2 certificate)
        {
            try
            {
                foreach (var extension in certificate.Extensions.Cast<X509Extension>()
                .Where(extension => extension.Oid.Value.Equals(AuthorityKeyOid)))
                {
                    using (var asnStream = new Asn1InputStream(extension.RawData))
                    {
                        var asnObject = asnStream.ReadObject();
                        var taggedObject = new DerTaggedObject(0, asnObject);

                        var authorityKey = AuthorityKeyIdentifier.GetInstance(taggedObject, true);
                        var octetString = new DerOctetString(authorityKey.GetKeyIdentifier());
                        return NormalizeOctetString(octetString.ToString());
                    }
                }

                return "";
            }
            catch (Exception e)
            {
                Log.WarnFormat("An issue occurred while attempting to extract the authority key from a certificate: {0}", e.Message);
                return "";
            }
        }
开发者ID:jardrake03,项目名称:incert,代码行数:26,代码来源:CertificateUtilities.cs

示例6: Parse

        /**
        * Parse the ServerCertificate message.
        *
        * @param is The stream where to parse from.
        * @return A Certificate object with the certs, the server has sended.
        * @throws IOException If something goes wrong during parsing.
        */
        internal static Certificate Parse(
			Stream inStr)
        {
            X509CertificateStructure[] certs;
            int left = TlsUtilities.ReadUint24(inStr);
            ArrayList tmp = new ArrayList();
            while (left > 0)
            {
                int size = TlsUtilities.ReadUint24(inStr);
                left -= 3 + size;
                byte[] buf = new byte[size];
                TlsUtilities.ReadFully(buf, inStr);
                MemoryStream bis = new MemoryStream(buf, false);
                Asn1InputStream ais = new Asn1InputStream(bis);
                Asn1Object o = ais.ReadObject();
                tmp.Add(X509CertificateStructure.GetInstance(o));
            //				if (bis.available() > 0)
                if (bis.Position < bis.Length)
                {
                    throw new ArgumentException("Sorry, there is garbage data left after the certificate");
                }
            }
            //			certs = new X509CertificateStructure[tmp.size()];
            //			for (int i = 0; i < tmp.size(); i++)
            //			{
            //				certs[i] = (X509CertificateStructure)tmp.elementAt(i);
            //			}
            certs = (X509CertificateStructure[]) tmp.ToArray(typeof(X509CertificateStructure));
            return new Certificate(certs);
        }
开发者ID:Noyabronok,项目名称:itextsharpml,代码行数:37,代码来源:Certificate.cs

示例7: ReadDerCrossCertificatePair

		private X509CertificatePair ReadDerCrossCertificatePair(
			Stream inStream)
		{
			Asn1InputStream dIn = new Asn1InputStream(inStream);//, ProviderUtil.getReadLimit(in));
			Asn1Sequence seq = (Asn1Sequence)dIn.ReadObject();
			CertificatePair pair = CertificatePair.GetInstance(seq);
			return new X509CertificatePair(pair);
		}
开发者ID:pusp,项目名称:o2platform,代码行数:8,代码来源:X509CertPairParser.cs

示例8: ExtractCrlDistributionPointsExtension

        static CrlDistPoint ExtractCrlDistributionPointsExtension(X509Certificate2 certificate)
        {
            var bouncyCastleCertificate = new X509CertificateParser().ReadCertificate(certificate.RawData);
            var extension = bouncyCastleCertificate.GetExtensionValue(new DerObjectIdentifier(ObjectIdentifiers.CrlDistributionPointsExtension));
            var stream = new Asn1InputStream(extension.GetOctetStream());

            return CrlDistPoint.GetInstance(stream.ReadObject());
        }
开发者ID:kiniry-supervision,项目名称:OpenNemID,代码行数:8,代码来源:CrlDistributionPointsExtractor.cs

示例9: SODFile

        /// <summary>
        /// Constructs a new EF_SOD file.
        /// </summary>
        /// <param name="data">bytes of the EF_DG1 file</param>
        public SODFile(byte[] data)
        {
            MemoryStream dataStream = new MemoryStream(data);
            BERTLVInputStream tlvStream = new BERTLVInputStream(dataStream);
            int tag = tlvStream.readTag();
            if (tag != IDGFile.EF_SOD_TAG) throw new ArgumentException("Expected EF_SOD_TAG");
            int length = tlvStream.readLength();

            Asn1InputStream sodAsn1 = new Asn1InputStream(dataStream);
            DerSequence seq = (DerSequence)sodAsn1.ReadObject();
            DerObjectIdentifier objectIdentifier = (DerObjectIdentifier)seq[0];

            //DerTaggedObject o = (DerTaggedObject)seq[1];
            DerSequence s2 = (DerSequence)((DerTaggedObject)seq[1]).GetObject();
            IEnumerator e = s2.GetEnumerator();
            e.MoveNext();
            DerInteger version = (DerInteger)e.Current;
            e.MoveNext();
            Asn1Set digestAlgorithms = (Asn1Set)e.Current;
            e.MoveNext();
            ContentInfo contentInfo = ContentInfo.GetInstance(e.Current);

            Asn1Set signerInfos = null;
            bool certsBer = false;
            bool crlsBer = false;
            Asn1Set certificates = null;
            Asn1Set crls = null;

            while (e.MoveNext())
            {
                Object o = e.Current;
                if (o is Asn1TaggedObject)
                {
                    Asn1TaggedObject tagged = (Asn1TaggedObject)o;
                    switch (tagged.TagNo)
                    {
                        case 0:
                            certsBer = tagged is BerTaggedObject;
                            certificates = Asn1Set.GetInstance(tagged, false);
                            break;
                        case 1:
                            crlsBer = tagged is BerTaggedObject;
                            crls = Asn1Set.GetInstance(tagged, false);
                            break;
                        default:
                            throw new ArgumentException("unknown tag value " + tagged.TagNo);
                    }
                }
                else
                {
                    signerInfos = (Asn1Set)o;
                }
            }
            _signedData = new SignedData(digestAlgorithms, contentInfo, certificates, crls, signerInfos);
            byte[] content = ((DerOctetString)contentInfo.Content).GetOctets();
            Asn1InputStream inStream = new Asn1InputStream(content);
            _lds = new LdsSecurityObject((Asn1Sequence)inStream.ReadObject());
        }
开发者ID:hernandazevedo,项目名称:JMRTD,代码行数:62,代码来源:SODFile.cs

示例10: GetECDiffieHellmanCngPublicKey

 private static ECDiffieHellmanCngPublicKey GetECDiffieHellmanCngPublicKey(X509Certificate2 cert)
 {
     var keyAlgoDerBytes = cert.GetKeyAlgorithmParameters();
     var keyAlgoAsn1 = new Asn1InputStream(keyAlgoDerBytes).ReadObject();
     var keyAlgoOid = new DerObjectIdentifier(keyAlgoAsn1.ToString());
     var xmlImport = Rfc4050XmlMaker("ECDH", keyAlgoOid, cert);
     var ecDiffieHellmanCngPublicKey = ECDiffieHellmanCngPublicKey.FromXmlString(xmlImport);
     return ecDiffieHellmanCngPublicKey;
 }
开发者ID:sidshetye,项目名称:win10secp384Issue,代码行数:9,代码来源:Program.cs

示例11: verifySignature

		public Boolean verifySignature(Byte[] data, Byte[] sig)
		{
			ECDsaSigner signer = new ECDsaSigner();
			signer.Init(false, new ECPublicKeyParameters(ecParams.Curve.DecodePoint(pubKey), ecParams));
			using (Asn1InputStream asn1stream = new Asn1InputStream(sig))
			{
				Asn1Sequence seq = (Asn1Sequence)asn1stream.ReadObject();
				return signer.VerifySignature(data, ((DerInteger)seq[0]).PositiveValue, ((DerInteger)seq[1]).PositiveValue);
			}
		}
开发者ID:jmassey-bitpay,项目名称:bitpay-csharp-client-csr,代码行数:10,代码来源:ECKey.cs

示例12: Main

        public static void Main(string[] args)
        {
            FileStream fIn = new FileStream(args[0], FileMode.Open);
            Asn1InputStream bIn = new Asn1InputStream(fIn);

            Asn1Object obj;
            while ((obj = bIn.ReadObject()) != null)
            {
                Console.WriteLine(Asn1Dump.DumpAsString(obj));
            }
        }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:11,代码来源:Dump.cs

示例13: OcspResp

		private OcspResp(
			Asn1InputStream aIn)
		{
			try
			{
				this.resp = OcspResponse.GetInstance(aIn.ReadObject());
			}
			catch (Exception e)
			{
				throw new IOException("malformed response: " + e.Message, e);
			}
		}
开发者ID:MBrekhof,项目名称:pleiobox-clients,代码行数:12,代码来源:OCSPResp.cs

示例14: Main

        public static void Main(string[] args)
        {
            FileStream fIn = File.OpenRead(args[0]);
            Asn1InputStream bIn = new Asn1InputStream(fIn);

			Asn1Object obj;
			while ((obj = bIn.ReadObject()) != null)
            {
                System.Diagnostics.Debug.WriteLine(Asn1Dump.DumpAsString(obj));
            }

			bIn.Close();
        }
开发者ID:roryshko,项目名称:BouncyCastle.Crypto,代码行数:13,代码来源:Dump.cs

示例15: GetCertificatePolicyOid

 public static String GetCertificatePolicyOid(X509Certificate2 certificate)
 {
     var extensions = GetX509Extensions(certificate);
     var e = extensions.GetExtension(X509Extensions.CertificatePolicies);
     var extIn = new Asn1InputStream(e.Value.GetOctetStream());
     var piSeq = (DerSequence)extIn.ReadObject();
     if (piSeq.Count != 1)
     {
         throw new NonOcesCertificateException("Could not find Certificate PolicyOID");
     }
     var pi = PolicyInformation.GetInstance(piSeq[0]);
     return pi.PolicyIdentifier.Id;
 }
开发者ID:kiniry-supervision,项目名称:OpenNemID,代码行数:13,代码来源:X509CertificatePropertyExtrator.cs


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