Example #1
0
        protected virtual void LoadKeyBag(PrivateKeyInfo privKeyInfo, Asn1Set bagAttributes)
        {
            AsymmetricKeyParameter key        = PrivateKeyFactory.CreateKey(privKeyInfo);
            IDictionary            dictionary = Platform.CreateHashtable();
            AsymmetricKeyEntry     value      = new AsymmetricKeyEntry(key, dictionary);
            string          text            = null;
            Asn1OctetString asn1OctetString = null;

            if (bagAttributes != null)
            {
                foreach (Asn1Sequence asn1Sequence in bagAttributes)
                {
                    DerObjectIdentifier instance  = DerObjectIdentifier.GetInstance(asn1Sequence[0]);
                    Asn1Set             instance2 = Asn1Set.GetInstance(asn1Sequence[1]);
                    if (instance2.Count > 0)
                    {
                        Asn1Encodable asn1Encodable = instance2[0];
                        if (dictionary.Contains(instance.Id))
                        {
                            if (!dictionary[instance.Id].Equals(asn1Encodable))
                            {
                                throw new IOException("attempt to add existing attribute with different value");
                            }
                        }
                        else
                        {
                            dictionary.Add(instance.Id, asn1Encodable);
                        }
                        if (instance.Equals(PkcsObjectIdentifiers.Pkcs9AtFriendlyName))
                        {
                            text            = ((DerBmpString)asn1Encodable).GetString();
                            this.keys[text] = value;
                        }
                        else if (instance.Equals(PkcsObjectIdentifiers.Pkcs9AtLocalKeyID))
                        {
                            asn1OctetString = (Asn1OctetString)asn1Encodable;
                        }
                    }
                }
            }
            if (asn1OctetString == null)
            {
                this.unmarkedKeyEntry = value;
                return;
            }
            string text2 = Hex.ToHexString(asn1OctetString.GetOctets());

            if (text == null)
            {
                this.keys[text2] = value;
                return;
            }
            this.localIds[text] = text2;
        }
Example #2
0
    private static ICollection GetAlternativeName(Asn1OctetString extVal)
    {
        IList list = Platform.CreateArrayList();

        if (extVal != null)
        {
            try
            {
                Asn1Sequence instance = Asn1Sequence.GetInstance(FromExtensionValue(extVal));
                foreach (GeneralName item in instance)
                {
                    IList list2 = Platform.CreateArrayList();
                    list2.Add(item.TagNo);
                    switch (item.TagNo)
                    {
                    case 0:
                    case 3:
                    case 5:
                        list2.Add(item.Name.ToAsn1Object());
                        break;

                    case 4:
                        list2.Add(X509Name.GetInstance(item.Name).ToString());
                        break;

                    case 1:
                    case 2:
                    case 6:
                        list2.Add(((IAsn1String)item.Name).GetString());
                        break;

                    case 8:
                        list2.Add(DerObjectIdentifier.GetInstance(item.Name).Id);
                        break;

                    case 7:
                        list2.Add(Asn1OctetString.GetInstance(item.Name).GetOctets());
                        break;

                    default:
                        throw new IOException("Bad tag number: " + item.TagNo);
                    }
                    list.Add(list2);
                }
                return(list);
            }
            catch (Exception ex)
            {
                throw new CertificateParsingException(ex.Message);
            }
        }
        return(list);
    }
 private PolicyInformation(Asn1Sequence seq)
 {
     if (seq.Count < 1 || seq.Count > 2)
     {
         throw new ArgumentException("Bad sequence size: " + seq.Count);
     }
     this.policyIdentifier = DerObjectIdentifier.GetInstance(seq[0]);
     if (seq.Count > 1)
     {
         this.policyQualifiers = Asn1Sequence.GetInstance(seq[1]);
     }
 }
 private PolicyInformation(Asn1Sequence seq)
 {
     //IL_002d: Unknown result type (might be due to invalid IL or missing references)
     if (seq.Count < 1 || seq.Count > 2)
     {
         throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count));
     }
     policyIdentifier = DerObjectIdentifier.GetInstance(seq[0]);
     if (seq.Count > 1)
     {
         policyQualifiers = Asn1Sequence.GetInstance(seq[1]);
     }
 }
Example #5
0
        private TstInfo(Asn1Sequence seq)
        {
            //IL_00fa: Unknown result type (might be due to invalid IL or missing references)
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            enumerator.MoveNext();
            version = DerInteger.GetInstance(enumerator.get_Current());
            enumerator.MoveNext();
            tsaPolicyId = DerObjectIdentifier.GetInstance(enumerator.get_Current());
            enumerator.MoveNext();
            messageImprint = MessageImprint.GetInstance(enumerator.get_Current());
            enumerator.MoveNext();
            serialNumber = DerInteger.GetInstance(enumerator.get_Current());
            enumerator.MoveNext();
            genTime  = DerGeneralizedTime.GetInstance(enumerator.get_Current());
            ordering = DerBoolean.False;
            while (enumerator.MoveNext())
            {
                Asn1Object asn1Object = (Asn1Object)enumerator.get_Current();
                if (asn1Object is Asn1TaggedObject)
                {
                    DerTaggedObject derTaggedObject = (DerTaggedObject)asn1Object;
                    switch (derTaggedObject.TagNo)
                    {
                    case 0:
                        tsa = GeneralName.GetInstance(derTaggedObject, explicitly: true);
                        break;

                    case 1:
                        extensions = X509Extensions.GetInstance(derTaggedObject, explicitly: false);
                        break;

                    default:
                        throw new ArgumentException(string.Concat((object)"Unknown tag value ", (object)derTaggedObject.TagNo));
                    }
                }
                if (asn1Object is DerSequence)
                {
                    accuracy = Accuracy.GetInstance(asn1Object);
                }
                if (asn1Object is DerBoolean)
                {
                    ordering = DerBoolean.GetInstance(asn1Object);
                }
                if (asn1Object is DerInteger)
                {
                    nonce = DerInteger.GetInstance(asn1Object);
                }
            }
        }
Example #6
0
        public AlgorithmIdentifierBouncy(Asn1Sequence seq)
        {
            if (seq == null)
            {
                throw new ArgumentNullException("seq");
            }

            if (seq.Count < 1 || seq.Count > 2)
            {
                throw new ArgumentException("Invalid number of sequence members");
            }

            Algorithm  = DerObjectIdentifier.GetInstance(seq[0]);
            Parameters = (seq.Count == 2) ? seq[1] : null;
        }