summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-06-27 21:11:59 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-06-27 21:11:59 +0700
commit35cfd51633bbbbc92c2c17c76646e9a9dc945b11 (patch)
tree563cda15bf08c63de832198be2b9e0263bae5e60 /crypto
parentSplit up fast/slow tests (diff)
downloadBouncyCastle.NET-ed25519-35cfd51633bbbbc92c2c17c76646e9a9dc945b11.tar.xz
Generics migration in Asn1
Diffstat (limited to 'crypto')
-rw-r--r--crypto/src/asn1/Asn1EncodableVector.cs3
-rw-r--r--crypto/src/asn1/Asn1Sequence.cs3
-rw-r--r--crypto/src/asn1/Asn1Set.cs3
-rw-r--r--crypto/src/asn1/LazyDLEnumerator.cs3
-rw-r--r--crypto/src/asn1/cms/AttributeTable.cs174
-rw-r--r--crypto/src/asn1/cms/ContentInfo.cs1
-rw-r--r--crypto/src/asn1/cms/SignedData.cs41
-rw-r--r--crypto/src/asn1/cms/SignerInfo.cs24
-rw-r--r--crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs14
-rw-r--r--crypto/src/asn1/cryptopro/GOST28147Parameters.cs19
-rw-r--r--crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs16
-rw-r--r--crypto/src/asn1/esf/SignerLocation.cs37
-rw-r--r--crypto/src/asn1/icao/DataGroupHash.cs9
-rw-r--r--crypto/src/asn1/icao/LDSSecurityObject.cs9
-rw-r--r--crypto/src/asn1/isismtt/x509/Admissions.cs59
-rw-r--r--crypto/src/asn1/isismtt/x509/NamingAuthority.cs39
-rw-r--r--crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs55
-rw-r--r--crypto/src/asn1/isismtt/x509/ProfessionInfo.cs54
-rw-r--r--crypto/src/asn1/isismtt/x509/Restriction.cs9
-rw-r--r--crypto/src/asn1/ocsp/CrlID.cs6
-rw-r--r--crypto/src/asn1/oiw/ElGamalParameter.cs2
-rw-r--r--crypto/src/asn1/pkcs/ContentInfo.cs3
-rw-r--r--crypto/src/asn1/pkcs/DHParameter.cs6
-rw-r--r--crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs10
-rw-r--r--crypto/src/asn1/pkcs/PBEParameter.cs1
-rw-r--r--crypto/src/asn1/pkcs/PrivateKeyInfo.cs4
-rw-r--r--crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs2
-rw-r--r--crypto/src/asn1/pkcs/SignedData.cs27
-rw-r--r--crypto/src/asn1/pkcs/SignerInfo.cs9
-rw-r--r--crypto/src/asn1/smime/SMIMECapabilities.cs32
-rw-r--r--crypto/src/asn1/tsp/TSTInfo.cs8
-rw-r--r--crypto/src/asn1/x500/style/IetfUtilities.cs1
-rw-r--r--crypto/src/asn1/x509/AttributeTable.cs39
-rw-r--r--crypto/src/asn1/x509/AuthorityInformationAccess.cs2
-rw-r--r--crypto/src/asn1/x509/AuthorityKeyIdentifier.cs2
-rw-r--r--crypto/src/asn1/x509/CertificateList.cs6
-rw-r--r--crypto/src/asn1/x509/DSAParameter.cs1
-rw-r--r--crypto/src/asn1/x509/DigestInfo.cs1
-rw-r--r--crypto/src/asn1/x509/ExtendedKeyUsage.cs30
-rw-r--r--crypto/src/asn1/x509/GeneralName.cs7
-rw-r--r--crypto/src/asn1/x509/IetfAttrSyntax.cs3
-rw-r--r--crypto/src/asn1/x509/NameConstraints.cs20
-rw-r--r--crypto/src/asn1/x509/NoticeReference.cs6
-rw-r--r--crypto/src/asn1/x509/PolicyMappings.cs18
-rw-r--r--crypto/src/asn1/x509/RSAPublicKeyStructure.cs2
-rw-r--r--crypto/src/asn1/x509/SubjectDirectoryAttributes.cs26
-rw-r--r--crypto/src/asn1/x509/SubjectPublicKeyInfo.cs1
-rw-r--r--crypto/src/asn1/x509/TBSCertList.cs46
-rw-r--r--crypto/src/asn1/x509/X509ExtensionsGenerator.cs19
-rw-r--r--crypto/src/asn1/x509/X509Name.cs215
-rw-r--r--crypto/src/asn1/x509/qualified/MonetaryValue.cs1
-rw-r--r--crypto/src/asn1/x509/qualified/SemanticsInformation.cs28
-rw-r--r--crypto/src/asn1/x509/sigi/NameOrPseudonym.cs1
-rw-r--r--crypto/src/asn1/x509/sigi/PersonalData.cs40
-rw-r--r--crypto/src/asn1/x9/DHDomainParameters.cs6
-rw-r--r--crypto/src/asn1/x9/KeySpecificInfo.cs7
-rw-r--r--crypto/src/asn1/x9/OtherInfo.cs15
-rw-r--r--crypto/src/cms/CMSSignedDataGenerator.cs9
-rw-r--r--crypto/src/cms/CMSSignedDataStreamGenerator.cs4
-rw-r--r--crypto/src/cms/DefaultAuthenticatedAttributeTableGenerator.cs25
-rw-r--r--crypto/src/cms/DefaultSignedAttributeTableGenerator.cs48
-rw-r--r--crypto/src/pkix/Rfc3281CertPathUtilities.cs2
-rw-r--r--crypto/src/tsp/TimeStampTokenGenerator.cs6
-rw-r--r--crypto/src/util/collections/EnumerableProxy.cs4
-rw-r--r--crypto/src/util/collections/ReadOnlyList.cs3
-rw-r--r--crypto/src/util/collections/UnmodifiableDictionary.cs2
-rw-r--r--crypto/test/src/asn1/test/AttributeTableUnitTest.cs2
-rw-r--r--crypto/test/src/asn1/test/ParseTest.cs2
-rw-r--r--crypto/test/src/asn1/test/X509NameTest.cs14
-rw-r--r--crypto/test/src/cmp/test/ProtectedMessageTest.cs7
-rw-r--r--crypto/test/src/cms/test/SignedDataStreamTest.cs5
-rw-r--r--crypto/test/src/pkcs/test/PKCS10Test.cs16
-rw-r--r--crypto/test/src/pkcs/test/PKCS12StoreTest.cs7
-rw-r--r--crypto/test/src/security/test/TestDotNetUtil.cs12
-rw-r--r--crypto/test/src/test/CertTest.cs20
-rw-r--r--crypto/test/src/test/PKCS10CertRequestTest.cs4
-rw-r--r--crypto/test/src/test/PkixPolicyMappingTest.cs22
-rw-r--r--crypto/test/src/tsp/test/NewTspTest.cs4
-rw-r--r--crypto/test/src/tsp/test/TSPTest.cs15
-rw-r--r--crypto/test/src/x509/test/TestCertificateGen.cs20
80 files changed, 600 insertions, 878 deletions
diff --git a/crypto/src/asn1/Asn1EncodableVector.cs b/crypto/src/asn1/Asn1EncodableVector.cs
index 7560968b6..b4249b7c0 100644
--- a/crypto/src/asn1/Asn1EncodableVector.cs
+++ b/crypto/src/asn1/Asn1EncodableVector.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
 
 namespace Org.BouncyCastle.Asn1
@@ -141,7 +140,7 @@ namespace Org.BouncyCastle.Asn1
             get { return elementCount; }
         }
 
-        IEnumerator IEnumerable.GetEnumerator()
+        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
         {
             return GetEnumerator();
         }
diff --git a/crypto/src/asn1/Asn1Sequence.cs b/crypto/src/asn1/Asn1Sequence.cs
index fea5a6984..d164b32f1 100644
--- a/crypto/src/asn1/Asn1Sequence.cs
+++ b/crypto/src/asn1/Asn1Sequence.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 
@@ -113,7 +112,7 @@ namespace Org.BouncyCastle.Asn1
             this.elements = elementVector.TakeElements();
         }
 
-        IEnumerator IEnumerable.GetEnumerator()
+        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
         {
             return GetEnumerator();
         }
diff --git a/crypto/src/asn1/Asn1Set.cs b/crypto/src/asn1/Asn1Set.cs
index f9bfd21c3..1045b7f74 100644
--- a/crypto/src/asn1/Asn1Set.cs
+++ b/crypto/src/asn1/Asn1Set.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
@@ -136,7 +135,7 @@ namespace Org.BouncyCastle.Asn1
             this.isSorted = isSorted || elements.Length < 2;
         }
 
-        IEnumerator IEnumerable.GetEnumerator()
+        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
         {
             return GetEnumerator();
         }
diff --git a/crypto/src/asn1/LazyDLEnumerator.cs b/crypto/src/asn1/LazyDLEnumerator.cs
index 5e1be8228..b71cb49e9 100644
--- a/crypto/src/asn1/LazyDLEnumerator.cs
+++ b/crypto/src/asn1/LazyDLEnumerator.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 
@@ -20,7 +19,7 @@ namespace Org.BouncyCastle.Asn1
             Reset();
         }
 
-        object IEnumerator.Current
+        object System.Collections.IEnumerator.Current
         {
             get { return Current; }
         }
diff --git a/crypto/src/asn1/cms/AttributeTable.cs b/crypto/src/asn1/cms/AttributeTable.cs
index e20e6e9b2..aa312a13f 100644
--- a/crypto/src/asn1/cms/AttributeTable.cs
+++ b/crypto/src/asn1/cms/AttributeTable.cs
@@ -1,5 +1,5 @@
 using System;
-using System.Collections;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Utilities;
 
@@ -7,76 +7,64 @@ namespace Org.BouncyCastle.Asn1.Cms
 {
     public class AttributeTable
     {
-        private readonly IDictionary attributes;
+        private readonly Dictionary<DerObjectIdentifier, object> m_attributes;
 
-        public AttributeTable(
-            IDictionary attrs)
+        public AttributeTable(IDictionary<DerObjectIdentifier, object> attrs)
         {
-            this.attributes = Platform.CreateHashtable(attrs);
+            m_attributes = new Dictionary<DerObjectIdentifier, object>(attrs);
         }
 
-        public AttributeTable(
-            Asn1EncodableVector v)
+        public AttributeTable(Asn1EncodableVector v)
         {
-            this.attributes = Platform.CreateHashtable(v.Count);
+            m_attributes = new Dictionary<DerObjectIdentifier, object>(v.Count);
 
-			foreach (Asn1Encodable o in v)
+            foreach (Asn1Encodable e in v)
             {
-                Attribute a = Attribute.GetInstance(o);
-
-				AddAttribute(a);
+				AddAttribute(Attribute.GetInstance(e));
             }
         }
 
-        public AttributeTable(
-            Asn1Set s)
+        public AttributeTable(Asn1Set s)
         {
-            this.attributes = Platform.CreateHashtable(s.Count);
+            m_attributes = new Dictionary<DerObjectIdentifier, object>(s.Count);
 
-			for (int i = 0; i != s.Count; i++)
+            foreach (Asn1Encodable e in s)
             {
-                Attribute a = Attribute.GetInstance(s[i]);
-
-                AddAttribute(a);
+                AddAttribute(Attribute.GetInstance(e));
             }
         }
 
-		public AttributeTable(
-			Attributes attrs)
+		public AttributeTable(Attributes attrs)
 			: this(Asn1Set.GetInstance(attrs.ToAsn1Object()))
 		{
 		}
 
-		private void AddAttribute(
-            Attribute a)
+		private void AddAttribute(Attribute a)
         {
 			DerObjectIdentifier oid = a.AttrType;
-            object obj = attributes[oid];
 
-            if (obj == null)
+            if (!m_attributes.TryGetValue(oid, out object existingValue))
             {
-                attributes[oid] = a;
+                m_attributes[oid] = a;
+                return;
             }
-            else
-            {
-                IList v;
-
-                if (obj is Attribute)
-                {
-                    v = Platform.CreateArrayList();
 
-                    v.Add(obj);
-                    v.Add(a);
-                }
-                else
-                {
-                    v = (IList) obj;
-
-                    v.Add(a);
-                }
+            if (existingValue is IList<Attribute> existingList)
+            {
+                existingList.Add(a);
+                return;
+            }
 
-                attributes[oid] = v;
+            if (existingValue is Attribute existingAttr)
+            {
+                var newList = new List<Attribute>();
+                newList.Add(existingAttr);
+                newList.Add(a);
+                m_attributes[oid] = newList;
+                return;
             }
+
+            throw new InvalidOperationException();
         }
 
 		/// <summary>Return the first attribute matching the given OBJECT IDENTIFIER</summary>
@@ -84,16 +72,18 @@ namespace Org.BouncyCastle.Asn1.Cms
 		{
 			get
 			{
-				object obj = attributes[oid];
+                if (!m_attributes.TryGetValue(oid, out object existingValue))
+                    return null;
 
-				if (obj is IList)
-				{
-					return (Attribute)((IList)obj)[0];
-				}
+                if (existingValue is IList<Attribute> existingList)
+                    return existingList[0];
 
-				return (Attribute) obj;
-			}
-		}
+                if (existingValue is Attribute existingAttr)
+                    return existingAttr;
+
+                throw new InvalidOperationException();
+            }
+        }
 
 		/**
         * Return all the attributes matching the OBJECT IDENTIFIER oid. The vector will be
@@ -102,26 +92,30 @@ namespace Org.BouncyCastle.Asn1.Cms
         * @param oid type of attribute required.
         * @return a vector of all the attributes found of type oid.
         */
-        public Asn1EncodableVector GetAll(
-            DerObjectIdentifier oid)
+        public Asn1EncodableVector GetAll(DerObjectIdentifier oid)
         {
             Asn1EncodableVector v = new Asn1EncodableVector();
 
-            object obj = attributes[oid];
-
-			if (obj is IList)
+            if (m_attributes.TryGetValue(oid, out object existingValue))
             {
-                foreach (Attribute a in (IList)obj)
+                if (existingValue is IList<Attribute> existingList)
                 {
-                    v.Add(a);
+                    foreach (var attr in existingList)
+                    {
+                        v.Add(attr);
+                    }
+                }
+                else if (existingValue is Attribute existingAttr)
+                {
+                    v.Add(existingAttr);
+                }
+                else
+                {
+                    throw new InvalidOperationException();
                 }
-            }
-            else if (obj != null)
-            {
-                v.Add((Attribute) obj);
             }
 
-			return v;
+            return v;
         }
 
 		public int Count
@@ -130,52 +124,60 @@ namespace Org.BouncyCastle.Asn1.Cms
 			{
 				int total = 0;
 
-				foreach (object o in attributes.Values)
-				{
-					if (o is IList)
-					{
-						total += ((IList)o).Count;
-					}
-					else
-					{
-						++total;
-					}
-				}
+                foreach (object existingValue in m_attributes.Values)
+                {
+                    if (existingValue is IList<Attribute> existingList)
+                    {
+                        total += existingList.Count;
+                    }
+                    else if (existingValue is Attribute existingAttr)
+                    {
+                        ++total;
+                    }
+                    else
+                    {
+                        throw new InvalidOperationException();
+                    }
+                }
 
 				return total;
 			}
 		}
 
-        public IDictionary ToDictionary()
+        public IDictionary<DerObjectIdentifier, object> ToDictionary()
         {
-            return Platform.CreateHashtable(attributes);
+            return new Dictionary<DerObjectIdentifier, object>(m_attributes);
         }
 
 		public Asn1EncodableVector ToAsn1EncodableVector()
         {
             Asn1EncodableVector v = new Asn1EncodableVector();
 
-			foreach (object obj in attributes.Values)
+            foreach (object existingValue in m_attributes.Values)
             {
-                if (obj is IList)
+                if (existingValue is IList<Attribute> existingList)
                 {
-                    foreach (object el in (IList)obj)
+                    foreach (Attribute existingAttr in existingList)
                     {
-                        v.Add(Attribute.GetInstance(el));
+                        v.Add(existingAttr);
                     }
                 }
+                else if (existingValue is Attribute existingAttr)
+                {
+                    v.Add(existingAttr);
+                }
                 else
                 {
-                    v.Add(Attribute.GetInstance(obj));
+                    throw new InvalidOperationException();
                 }
             }
 
-			return v;
+            return v;
         }
 
 		public Attributes ToAttributes()
 		{
-			return new Attributes(this.ToAsn1EncodableVector());
+			return new Attributes(ToAsn1EncodableVector());
 		}
 
 		/**
@@ -187,7 +189,7 @@ namespace Org.BouncyCastle.Asn1.Cms
 		 */
 		public AttributeTable Add(DerObjectIdentifier attrType, Asn1Encodable attrValue)
 		{
-			AttributeTable newTable = new AttributeTable(attributes);
+			AttributeTable newTable = new AttributeTable(m_attributes);
 
 			newTable.AddAttribute(new Attribute(attrType, new DerSet(attrValue)));
 
@@ -196,9 +198,9 @@ namespace Org.BouncyCastle.Asn1.Cms
 
 		public AttributeTable Remove(DerObjectIdentifier attrType)
 		{
-			AttributeTable newTable = new AttributeTable(attributes);
+			AttributeTable newTable = new AttributeTable(m_attributes);
 
-			newTable.attributes.Remove(attrType);
+			newTable.m_attributes.Remove(attrType);
 
 			return newTable;
 		}
diff --git a/crypto/src/asn1/cms/ContentInfo.cs b/crypto/src/asn1/cms/ContentInfo.cs
index f130a4bc7..847df6dd8 100644
--- a/crypto/src/asn1/cms/ContentInfo.cs
+++ b/crypto/src/asn1/cms/ContentInfo.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Utilities;
 
diff --git a/crypto/src/asn1/cms/SignedData.cs b/crypto/src/asn1/cms/SignedData.cs
index 1e97346e6..789f8bd72 100644
--- a/crypto/src/asn1/cms/SignedData.cs
+++ b/crypto/src/asn1/cms/SignedData.cs
@@ -1,7 +1,4 @@
 using System;
-using System.Collections;
-
-using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.Cms
 {
@@ -140,8 +137,7 @@ namespace Org.BouncyCastle.Asn1.Cms
             return Version1;
         }
 
-        private bool CheckForVersion3(
-            Asn1Set signerInfs)
+        private bool CheckForVersion3(Asn1Set signerInfs)
         {
             foreach (object obj in signerInfs)
             {
@@ -156,45 +152,42 @@ namespace Org.BouncyCastle.Asn1.Cms
             return false;
         }
 
-        private SignedData(
-            Asn1Sequence seq)
+        private SignedData(Asn1Sequence seq)
         {
-            IEnumerator e = seq.GetEnumerator();
+            var e = seq.GetEnumerator();
 
             e.MoveNext();
             version = (DerInteger)e.Current;
 
             e.MoveNext();
-            digestAlgorithms = ((Asn1Set)e.Current);
+            digestAlgorithms = (Asn1Set)e.Current.ToAsn1Object();
 
             e.MoveNext();
-            contentInfo = ContentInfo.GetInstance(e.Current);
+            contentInfo = ContentInfo.GetInstance(e.Current.ToAsn1Object());
 
             while (e.MoveNext())
             {
-                Asn1Object o = (Asn1Object)e.Current;
+                Asn1Object o = e.Current.ToAsn1Object();
 
                 //
                 // an interesting feature of SignedData is that there appear
                 // to be varying implementations...
                 // for the moment we ignore anything which doesn't fit.
                 //
-                if (o is Asn1TaggedObject)
+                if (o is Asn1TaggedObject tagged)
                 {
-                    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);
+                    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
diff --git a/crypto/src/asn1/cms/SignerInfo.cs b/crypto/src/asn1/cms/SignerInfo.cs
index 82ed04082..dbd0125c4 100644
--- a/crypto/src/asn1/cms/SignerInfo.cs
+++ b/crypto/src/asn1/cms/SignerInfo.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Utilities;
@@ -17,8 +16,7 @@ namespace Org.BouncyCastle.Asn1.Cms
         private Asn1OctetString         encryptedDigest;
         private Asn1Set                 unauthenticatedAttributes;
 
-        public static SignerInfo GetInstance(
-            object obj)
+        public static SignerInfo GetInstance(object obj)
         {
             if (obj == null || obj is SignerInfo)
                 return (SignerInfo) obj;
@@ -65,26 +63,26 @@ namespace Org.BouncyCastle.Asn1.Cms
 
         private SignerInfo(Asn1Sequence seq)
         {
-            IEnumerator e = seq.GetEnumerator();
+            var e = seq.GetEnumerator();
 
             e.MoveNext();
-            version = (DerInteger) e.Current;
+            version = (DerInteger)e.Current;
 
             e.MoveNext();
-            sid = SignerIdentifier.GetInstance(e.Current);
+            sid = SignerIdentifier.GetInstance(e.Current.ToAsn1Object());
 
             e.MoveNext();
-            digAlgorithm = AlgorithmIdentifier.GetInstance(e.Current);
+            digAlgorithm = AlgorithmIdentifier.GetInstance(e.Current.ToAsn1Object());
 
             e.MoveNext();
-            object obj = e.Current;
+            var obj = e.Current.ToAsn1Object();
 
-            if (obj is Asn1TaggedObject)
+            if (obj is Asn1TaggedObject tagged)
             {
-                authenticatedAttributes = Asn1Set.GetInstance((Asn1TaggedObject) obj, false);
+                authenticatedAttributes = Asn1Set.GetInstance(tagged, false);
 
                 e.MoveNext();
-                digEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(e.Current);
+                digEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(e.Current.ToAsn1Object());
             }
             else
             {
@@ -93,11 +91,11 @@ namespace Org.BouncyCastle.Asn1.Cms
             }
 
             e.MoveNext();
-            encryptedDigest = DerOctetString.GetInstance(e.Current);
+            encryptedDigest = Asn1OctetString.GetInstance(e.Current.ToAsn1Object());
 
             if (e.MoveNext())
             {
-                unauthenticatedAttributes = Asn1Set.GetInstance((Asn1TaggedObject) e.Current, false);
+                unauthenticatedAttributes = Asn1Set.GetInstance((Asn1TaggedObject)e.Current.ToAsn1Object(), false);
             }
             else
             {
diff --git a/crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs b/crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs
index 8e568a229..87df3c4a9 100644
--- a/crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs
+++ b/crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Utilities;
@@ -11,25 +10,20 @@ namespace Org.BouncyCastle.Asn1.CryptoPro
     {
         internal readonly DerInteger p, q, a, b, x, y;
 
-        public static ECGost3410ParamSetParameters GetInstance(
-            Asn1TaggedObject	obj,
-            bool				explicitly)
+        public static ECGost3410ParamSetParameters GetInstance(Asn1TaggedObject obj, bool explicitly)
         {
             return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
         }
 
-        public static ECGost3410ParamSetParameters GetInstance(
-            object obj)
+        public static ECGost3410ParamSetParameters GetInstance(object obj)
         {
             if (obj == null || obj is ECGost3410ParamSetParameters)
             {
                 return (ECGost3410ParamSetParameters) obj;
             }
 
-            if (obj is Asn1Sequence)
-            {
-                return new ECGost3410ParamSetParameters((Asn1Sequence) obj);
-            }
+            if (obj is Asn1Sequence seq)
+                return new ECGost3410ParamSetParameters(seq);
 
             throw new ArgumentException("Invalid GOST3410Parameter: " + Platform.GetTypeName(obj));
         }
diff --git a/crypto/src/asn1/cryptopro/GOST28147Parameters.cs b/crypto/src/asn1/cryptopro/GOST28147Parameters.cs
index fc0d792d1..9167cd4b5 100644
--- a/crypto/src/asn1/cryptopro/GOST28147Parameters.cs
+++ b/crypto/src/asn1/cryptopro/GOST28147Parameters.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Utilities;
 
@@ -11,31 +10,23 @@ namespace Org.BouncyCastle.Asn1.CryptoPro
         private readonly Asn1OctetString iv;
         private readonly DerObjectIdentifier paramSet;
 
-		public static Gost28147Parameters GetInstance(
-            Asn1TaggedObject	obj,
-            bool				explicitly)
+		public static Gost28147Parameters GetInstance(Asn1TaggedObject obj, bool explicitly)
         {
             return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
         }
 
-		public static Gost28147Parameters GetInstance(
-            object obj)
+		public static Gost28147Parameters GetInstance(object obj)
         {
             if (obj == null || obj is Gost28147Parameters)
-            {
                 return (Gost28147Parameters) obj;
-            }
 
-            if (obj is Asn1Sequence)
-            {
-                return new Gost28147Parameters((Asn1Sequence) obj);
-            }
+            if (obj is Asn1Sequence seq)
+                return new Gost28147Parameters(seq);
 
             throw new ArgumentException("Invalid GOST3410Parameter: " + Platform.GetTypeName(obj));
         }
 
-        private Gost28147Parameters(
-            Asn1Sequence seq)
+        private Gost28147Parameters(Asn1Sequence seq)
         {
 			if (seq.Count != 2)
 				throw new ArgumentException("Wrong number of elements in sequence", "seq");
diff --git a/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs b/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs
index ee6ed8c99..c82e4248a 100644
--- a/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs
+++ b/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Utilities;
@@ -12,25 +11,18 @@ namespace Org.BouncyCastle.Asn1.CryptoPro
         private readonly int keySize;
         private readonly DerInteger	p, q, a;
 
-		public static Gost3410ParamSetParameters GetInstance(
-            Asn1TaggedObject	obj,
-            bool				explicitly)
+		public static Gost3410ParamSetParameters GetInstance(Asn1TaggedObject obj, bool explicitly)
         {
             return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
         }
 
-		public static Gost3410ParamSetParameters GetInstance(
-            object obj)
+		public static Gost3410ParamSetParameters GetInstance(object obj)
         {
             if (obj == null || obj is Gost3410ParamSetParameters)
-            {
                 return (Gost3410ParamSetParameters) obj;
-            }
 
-			if (obj is Asn1Sequence)
-            {
-                return new Gost3410ParamSetParameters((Asn1Sequence) obj);
-            }
+			if (obj is Asn1Sequence seq)
+                return new Gost3410ParamSetParameters(seq);
 
             throw new ArgumentException("Invalid GOST3410Parameter: " + Platform.GetTypeName(obj));
         }
diff --git a/crypto/src/asn1/esf/SignerLocation.cs b/crypto/src/asn1/esf/SignerLocation.cs
index 4c82d09fd..0e87812be 100644
--- a/crypto/src/asn1/esf/SignerLocation.cs
+++ b/crypto/src/asn1/esf/SignerLocation.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Asn1.X500;
 
@@ -24,27 +23,26 @@ namespace Org.BouncyCastle.Asn1.Esf
         private DirectoryString localityName;
         private Asn1Sequence postalAddress;
 
-		public SignerLocation(
-			Asn1Sequence seq)
+		public SignerLocation(Asn1Sequence seq)
 		{
 			foreach (Asn1TaggedObject obj in seq)
 			{
 				switch (obj.TagNo)
 				{
-					case 0:
-						this.countryName = DirectoryString.GetInstance(obj, true);
-						break;
-					case 1:
-                        this.localityName = DirectoryString.GetInstance(obj, true);
-						break;
-					case 2:
-						bool isExplicit = obj.IsExplicit();	// handle erroneous implicitly tagged sequences
-						this.postalAddress = Asn1Sequence.GetInstance(obj, isExplicit);
-						if (postalAddress != null && postalAddress.Count > 6)
-							throw new ArgumentException("postal address must contain less than 6 strings");
-						break;
-					default:
-						throw new ArgumentException("illegal tag");
+				case 0:
+					this.countryName = DirectoryString.GetInstance(obj, true);
+					break;
+				case 1:
+                    this.localityName = DirectoryString.GetInstance(obj, true);
+					break;
+				case 2:
+					bool isExplicit = obj.IsExplicit();	// handle erroneous implicitly tagged sequences
+					this.postalAddress = Asn1Sequence.GetInstance(obj, isExplicit);
+					if (postalAddress != null && postalAddress.Count > 6)
+						throw new ArgumentException("postal address must contain less than 6 strings");
+					break;
+				default:
+					throw new ArgumentException("illegal tag");
 				}
 			}
 		}
@@ -78,13 +76,10 @@ namespace Org.BouncyCastle.Asn1.Esf
         {
         }
 
-        public static SignerLocation GetInstance(
-			object obj)
+        public static SignerLocation GetInstance(object obj)
 		{
 			if (obj == null || obj is SignerLocation)
-			{
 				return (SignerLocation) obj;
-			}
 
 			return new SignerLocation(Asn1Sequence.GetInstance(obj));
 		}
diff --git a/crypto/src/asn1/icao/DataGroupHash.cs b/crypto/src/asn1/icao/DataGroupHash.cs
index bf83718f3..c4a674152 100644
--- a/crypto/src/asn1/icao/DataGroupHash.cs
+++ b/crypto/src/asn1/icao/DataGroupHash.cs
@@ -1,7 +1,4 @@
 using System;
-using System.Collections;
-
-using Org.BouncyCastle.Asn1;
 
 namespace Org.BouncyCastle.Asn1.Icao
 {
@@ -38,8 +35,7 @@ namespace Org.BouncyCastle.Asn1.Icao
         private readonly DerInteger dataGroupNumber;
         private readonly Asn1OctetString dataGroupHashValue;
 
-		public static DataGroupHash GetInstance(
-            object obj)
+		public static DataGroupHash GetInstance(object obj)
         {
             if (obj is DataGroupHash)
                 return (DataGroupHash)obj;
@@ -50,8 +46,7 @@ namespace Org.BouncyCastle.Asn1.Icao
 			return null;
 		}
 
-		private DataGroupHash(
-			Asn1Sequence seq)
+		private DataGroupHash(Asn1Sequence seq)
         {
 			if (seq.Count != 2)
 				throw new ArgumentException("Wrong number of elements in sequence", "seq");
diff --git a/crypto/src/asn1/icao/LDSSecurityObject.cs b/crypto/src/asn1/icao/LDSSecurityObject.cs
index 5d7331a4f..c379d76bb 100644
--- a/crypto/src/asn1/icao/LDSSecurityObject.cs
+++ b/crypto/src/asn1/icao/LDSSecurityObject.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Math;
@@ -31,8 +30,7 @@ namespace Org.BouncyCastle.Asn1.Icao
 		private DataGroupHash[] datagroupHash;
 		private LdsVersionInfo versionInfo;
 
-		public static LdsSecurityObject GetInstance(
-			object obj)
+		public static LdsSecurityObject GetInstance(object obj)
 		{
 			if (obj is LdsSecurityObject)
 				return (LdsSecurityObject)obj;
@@ -43,13 +41,12 @@ namespace Org.BouncyCastle.Asn1.Icao
 			return null;
 		}
 
-		private LdsSecurityObject(
-			Asn1Sequence seq)
+		private LdsSecurityObject(Asn1Sequence seq)
 		{
 			if (seq == null || seq.Count == 0)
 				throw new ArgumentException("null or empty sequence passed.");
 
-			IEnumerator e = seq.GetEnumerator();
+			var e = seq.GetEnumerator();
 
 			// version
 			e.MoveNext();
diff --git a/crypto/src/asn1/isismtt/x509/Admissions.cs b/crypto/src/asn1/isismtt/x509/Admissions.cs
index 2aa6764bb..42ebceb1c 100644
--- a/crypto/src/asn1/isismtt/x509/Admissions.cs
+++ b/crypto/src/asn1/isismtt/x509/Admissions.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Utilities;
@@ -30,18 +29,13 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 		private readonly NamingAuthority	namingAuthority;
 		private readonly Asn1Sequence		professionInfos;
 
-		public static Admissions GetInstance(
-			object obj)
+		public static Admissions GetInstance(object obj)
 		{
 			if (obj == null || obj is Admissions)
-			{
-				return (Admissions) obj;
-			}
+				return (Admissions)obj;
 
-			if (obj is Asn1Sequence)
-			{
-				return new Admissions((Asn1Sequence) obj);
-			}
+			if (obj is Asn1Sequence seq)
+				return new Admissions(seq);
 
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
 		}
@@ -62,44 +56,43 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 		*
 		* @param seq The ASN.1 sequence.
 		*/
-		private Admissions(
-			Asn1Sequence seq)
+		private Admissions(Asn1Sequence seq)
 		{
 			if (seq.Count > 3)
 				throw new ArgumentException("Bad sequence size: " + seq.Count);
 
-			IEnumerator e = seq.GetEnumerator();
+			var e = seq.GetEnumerator();
 
 			e.MoveNext();
-			Asn1Encodable o = (Asn1Encodable) e.Current;
-			if (o is Asn1TaggedObject)
+			Asn1Encodable o = e.Current;
+			if (o is Asn1TaggedObject tagged1)
 			{
-				switch (((Asn1TaggedObject)o).TagNo)
+				switch (tagged1.TagNo)
 				{
-					case 0:
-						admissionAuthority = GeneralName.GetInstance((Asn1TaggedObject)o, true);
-						break;
-					case 1:
-						namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true);
-						break;
-					default:
-						throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo);
+				case 0:
+					admissionAuthority = GeneralName.GetInstance((Asn1TaggedObject)o, true);
+					break;
+				case 1:
+					namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true);
+					break;
+				default:
+					throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo);
 				}
 				e.MoveNext();
-				o = (Asn1Encodable) e.Current;
+				o = e.Current;
 			}
-			if (o is Asn1TaggedObject)
+			if (o is Asn1TaggedObject tagged2)
 			{
-				switch (((Asn1TaggedObject)o).TagNo)
+				switch (tagged2.TagNo)
 				{
-					case 1:
-						namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true);
-						break;
-					default:
-						throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo);
+				case 1:
+					namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true);
+					break;
+				default:
+					throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo);
 				}
 				e.MoveNext();
-				o = (Asn1Encodable) e.Current;
+				o = e.Current;
 			}
 			professionInfos = Asn1Sequence.GetInstance(o);
 			if (e.MoveNext())
diff --git a/crypto/src/asn1/isismtt/x509/NamingAuthority.cs b/crypto/src/asn1/isismtt/x509/NamingAuthority.cs
index 543dcecc7..78ef25654 100644
--- a/crypto/src/asn1/isismtt/x509/NamingAuthority.cs
+++ b/crypto/src/asn1/isismtt/x509/NamingAuthority.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Asn1.X500;
 using Org.BouncyCastle.Utilities;
@@ -37,25 +36,18 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 		private readonly string					namingAuthorityUrl;
 		private readonly DirectoryString		namingAuthorityText;
 
-		public static NamingAuthority GetInstance(
-			object obj)
+		public static NamingAuthority GetInstance(object obj)
 		{
 			if (obj == null || obj is NamingAuthority)
-			{
 				return (NamingAuthority) obj;
-			}
 
-			if (obj is Asn1Sequence)
-			{
-				return new NamingAuthority((Asn1Sequence) obj);
-			}
+			if (obj is Asn1Sequence seq)
+				return new NamingAuthority(seq);
 
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
 		}
 
-		public static NamingAuthority GetInstance(
-			Asn1TaggedObject	obj,
-			bool				isExplicit)
+		public static NamingAuthority GetInstance(Asn1TaggedObject obj, bool isExplicit)
 		{
 			return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
 		}
@@ -75,24 +67,23 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 		*
 		* @param seq The ASN.1 sequence.
 		*/
-		private NamingAuthority(
-			Asn1Sequence seq)
+		private NamingAuthority(Asn1Sequence seq)
 		{
 			if (seq.Count > 3)
 				throw new ArgumentException("Bad sequence size: " + seq.Count);
 
-			IEnumerator e = seq.GetEnumerator();
+			var e = seq.GetEnumerator();
 
 			if (e.MoveNext())
 			{
-				Asn1Encodable o = (Asn1Encodable) e.Current;
-				if (o is DerObjectIdentifier)
+				Asn1Encodable o = e.Current;
+				if (o is DerObjectIdentifier oid)
 				{
-					namingAuthorityID = (DerObjectIdentifier) o;
+					namingAuthorityID = oid;
 				}
-				else if (o is DerIA5String)
+				else if (o is DerIA5String ia5)
 				{
-					namingAuthorityUrl = DerIA5String.GetInstance(o).GetString();
+					namingAuthorityUrl = ia5.GetString();
 				}
 				else if (o is IAsn1String)
 				{
@@ -106,10 +97,10 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 
 			if (e.MoveNext())
 			{
-				Asn1Encodable o = (Asn1Encodable) e.Current;
-				if (o is DerIA5String)
+				Asn1Encodable o = e.Current;
+				if (o is DerIA5String ia5)
 				{
-					namingAuthorityUrl = DerIA5String.GetInstance(o).GetString();
+					namingAuthorityUrl = ia5.GetString();
 				}
 				else if (o is IAsn1String)
 				{
@@ -123,7 +114,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 
 			if (e.MoveNext())
 			{
-				Asn1Encodable o = (Asn1Encodable) e.Current;
+				Asn1Encodable o = e.Current;
 				if (o is IAsn1String)
 				{
 					namingAuthorityText = DirectoryString.GetInstance(o);
diff --git a/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs b/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs
index 60d3a88e8..23be2d388 100644
--- a/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs
+++ b/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Asn1.X500;
 using Org.BouncyCastle.Asn1.X509;
@@ -49,18 +48,13 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 		private readonly GeneralName		thirdPerson;
 		private readonly IssuerSerial		certRef;
 
-		public static ProcurationSyntax GetInstance(
-			object obj)
+		public static ProcurationSyntax GetInstance(object obj)
 		{
 			if (obj == null || obj is ProcurationSyntax)
-			{
 				return (ProcurationSyntax) obj;
-			}
 
-			if (obj is Asn1Sequence)
-			{
-				return new ProcurationSyntax((Asn1Sequence) obj);
-			}
+			if (obj is Asn1Sequence seq)
+				return new ProcurationSyntax(seq);
 
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
 		}
@@ -86,38 +80,37 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 		*
 		* @param seq The ASN.1 sequence.
 		*/
-		private ProcurationSyntax(
-			Asn1Sequence seq)
+		private ProcurationSyntax(Asn1Sequence seq)
 		{
 			if (seq.Count < 1 || seq.Count > 3)
 				throw new ArgumentException("Bad sequence size: " + seq.Count);
 
-			IEnumerator e = seq.GetEnumerator();
+			var e = seq.GetEnumerator();
 
 			while (e.MoveNext())
 			{
 				Asn1TaggedObject o = Asn1TaggedObject.GetInstance(e.Current);
 				switch (o.TagNo)
 				{
-					case 1:
-						country = DerPrintableString.GetInstance(o, true).GetString();
-						break;
-					case 2:
-						typeOfSubstitution = DirectoryString.GetInstance(o, true);
-						break;
-					case 3:
-						Asn1Object signingFor = o.GetObject();
-						if (signingFor is Asn1TaggedObject)
-						{
-							thirdPerson = GeneralName.GetInstance(signingFor);
-						}
-						else
-						{
-							certRef = IssuerSerial.GetInstance(signingFor);
-						}
-						break;
-					default:
-						throw new ArgumentException("Bad tag number: " + o.TagNo);
+				case 1:
+					country = DerPrintableString.GetInstance(o, true).GetString();
+					break;
+				case 2:
+					typeOfSubstitution = DirectoryString.GetInstance(o, true);
+					break;
+				case 3:
+					Asn1Object signingFor = o.GetObject();
+					if (signingFor is Asn1TaggedObject)
+					{
+						thirdPerson = GeneralName.GetInstance(signingFor);
+					}
+					else
+					{
+						certRef = IssuerSerial.GetInstance(signingFor);
+					}
+					break;
+				default:
+					throw new ArgumentException("Bad tag number: " + o.TagNo);
 				}
 			}
 		}
diff --git a/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs b/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs
index b65757c09..daa76730d 100644
--- a/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs
+++ b/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Asn1.X500;
 using Org.BouncyCastle.Utilities;
@@ -145,18 +144,13 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 		private readonly string				registrationNumber;
 		private readonly Asn1OctetString	addProfessionInfo;
 
-		public static ProfessionInfo GetInstance(
-			object obj)
+		public static ProfessionInfo GetInstance(object obj)
 		{
 			if (obj == null || obj is ProfessionInfo)
-			{
 				return (ProfessionInfo) obj;
-			}
 
-			if (obj is Asn1Sequence)
-			{
-				return new ProfessionInfo((Asn1Sequence) obj);
-			}
+			if (obj is Asn1Sequence seq)
+				return new ProfessionInfo(seq);
 
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
 		}
@@ -178,44 +172,42 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 		*
 		* @param seq The ASN.1 sequence.
 		*/
-		private ProfessionInfo(
-			Asn1Sequence seq)
+		private ProfessionInfo(Asn1Sequence seq)
 		{
 			if (seq.Count > 5)
 				throw new ArgumentException("Bad sequence size: " + seq.Count);
 
-			IEnumerator e = seq.GetEnumerator();
+			var e = seq.GetEnumerator();
 
 			e.MoveNext();
-			Asn1Encodable o = (Asn1Encodable) e.Current;
+			Asn1Encodable o = e.Current;
 
-			if (o is Asn1TaggedObject)
+			if (o is Asn1TaggedObject ato)
 			{
-				Asn1TaggedObject ato = (Asn1TaggedObject) o;
 				if (ato.TagNo != 0)
 					throw new ArgumentException("Bad tag number: " + ato.TagNo);
 
 				namingAuthority = NamingAuthority.GetInstance(ato, true);
 				e.MoveNext();
-				o = (Asn1Encodable) e.Current;
+				o = e.Current;
 			}
 
 			professionItems = Asn1Sequence.GetInstance(o);
 
 			if (e.MoveNext())
 			{
-				o = (Asn1Encodable) e.Current;
-				if (o is Asn1Sequence)
+				o = e.Current;
+				if (o is Asn1Sequence sequence)
 				{
-					professionOids = Asn1Sequence.GetInstance(o);
+					professionOids = sequence;
 				}
-				else if (o is DerPrintableString)
+				else if (o is DerPrintableString printable)
 				{
-					registrationNumber = DerPrintableString.GetInstance(o).GetString();
+					registrationNumber = printable.GetString();
 				}
-				else if (o is Asn1OctetString)
+				else if (o is Asn1OctetString octets)
 				{
-					addProfessionInfo = Asn1OctetString.GetInstance(o);
+					addProfessionInfo = octets;
 				}
 				else
 				{
@@ -225,14 +217,14 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 
 			if (e.MoveNext())
 			{
-				o = (Asn1Encodable) e.Current;
-				if (o is DerPrintableString)
+				o = e.Current;
+				if (o is DerPrintableString printable)
 				{
-					registrationNumber = DerPrintableString.GetInstance(o).GetString();
+					registrationNumber = printable.GetString();
 				}
-				else if (o is DerOctetString)
+				else if (o is Asn1OctetString octets)
 				{
-					addProfessionInfo = (DerOctetString) o;
+					addProfessionInfo = octets;
 				}
 				else
 				{
@@ -242,10 +234,10 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 
 			if (e.MoveNext())
 			{
-				o = (Asn1Encodable) e.Current;
-				if (o is DerOctetString)
+				o = e.Current;
+				if (o is Asn1OctetString octets)
 				{
-					addProfessionInfo = (DerOctetString) o;
+					addProfessionInfo = octets;
 				}
 				else
 				{
diff --git a/crypto/src/asn1/isismtt/x509/Restriction.cs b/crypto/src/asn1/isismtt/x509/Restriction.cs
index 75df25201..4334d331d 100644
--- a/crypto/src/asn1/isismtt/x509/Restriction.cs
+++ b/crypto/src/asn1/isismtt/x509/Restriction.cs
@@ -17,8 +17,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 	{
 		private readonly DirectoryString restriction;
 
-		public static Restriction GetInstance(
-			object obj)
+		public static Restriction GetInstance(object obj)
 		{
 			if (obj is Restriction)
 				return (Restriction) obj;
@@ -40,8 +39,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 		*
 		* @param restriction A IAsn1String.
 		*/
-		private Restriction(
-			DirectoryString restriction)
+		private Restriction(DirectoryString restriction)
 		{
 			this.restriction = restriction;
 		}
@@ -51,8 +49,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
 		*
 		* @param restriction The description of the restriction.
 		*/
-		public Restriction(
-			string restriction)
+		public Restriction(string restriction)
 		{
 			this.restriction = new DirectoryString(restriction);
 		}
diff --git a/crypto/src/asn1/ocsp/CrlID.cs b/crypto/src/asn1/ocsp/CrlID.cs
index 3b3869a7a..fc1e59d22 100644
--- a/crypto/src/asn1/ocsp/CrlID.cs
+++ b/crypto/src/asn1/ocsp/CrlID.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 namespace Org.BouncyCastle.Asn1.Ocsp
 {
@@ -10,9 +9,8 @@ namespace Org.BouncyCastle.Asn1.Ocsp
         private readonly DerInteger			crlNum;
         private readonly DerGeneralizedTime	crlTime;
 
-		// TODO Add GetInstance method(s) and amke this private?
-		public CrlID(
-            Asn1Sequence seq)
+		// TODO Add GetInstance method(s) and make this private?
+		public CrlID(Asn1Sequence seq)
         {
 			foreach (Asn1TaggedObject o in seq)
 			{
diff --git a/crypto/src/asn1/oiw/ElGamalParameter.cs b/crypto/src/asn1/oiw/ElGamalParameter.cs
index 3e020f059..b0a0ce348 100644
--- a/crypto/src/asn1/oiw/ElGamalParameter.cs
+++ b/crypto/src/asn1/oiw/ElGamalParameter.cs
@@ -1,7 +1,5 @@
 using System;
-using System.Collections;
 
-using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Math;
 
 namespace Org.BouncyCastle.Asn1.Oiw
diff --git a/crypto/src/asn1/pkcs/ContentInfo.cs b/crypto/src/asn1/pkcs/ContentInfo.cs
index 526a3c48e..d19b4659c 100644
--- a/crypto/src/asn1/pkcs/ContentInfo.cs
+++ b/crypto/src/asn1/pkcs/ContentInfo.cs
@@ -1,7 +1,4 @@
 using System;
-using System.Collections;
-
-using Org.BouncyCastle.Asn1;
 
 namespace Org.BouncyCastle.Asn1.Pkcs
 {
diff --git a/crypto/src/asn1/pkcs/DHParameter.cs b/crypto/src/asn1/pkcs/DHParameter.cs
index 23be5d2ab..7a07a18b0 100644
--- a/crypto/src/asn1/pkcs/DHParameter.cs
+++ b/crypto/src/asn1/pkcs/DHParameter.cs
@@ -1,7 +1,3 @@
-using Org.BouncyCastle.Asn1;
-using System;
-using System.Collections;
-
 using Org.BouncyCastle.Math;
 
 namespace Org.BouncyCastle.Asn1.Pkcs
@@ -28,7 +24,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs
 		public DHParameter(
             Asn1Sequence seq)
         {
-            IEnumerator e = seq.GetEnumerator();
+            var e = seq.GetEnumerator();
 
 			e.MoveNext();
             p = (DerInteger)e.Current;
diff --git a/crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs b/crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs
index 987027009..5ca612f27 100644
--- a/crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs
+++ b/crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Utilities;
@@ -12,8 +11,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs
         private readonly AlgorithmIdentifier algId;
         private readonly Asn1OctetString data;
 
-		private EncryptedPrivateKeyInfo(
-            Asn1Sequence seq)
+		private EncryptedPrivateKeyInfo(Asn1Sequence seq)
         {
 			if (seq.Count != 2)
 				throw new ArgumentException("Wrong number of elements in sequence", "seq");
@@ -38,10 +36,8 @@ namespace Org.BouncyCastle.Asn1.Pkcs
 				return (EncryptedPrivateKeyInfo) obj;
 			}
 
-			if (obj is Asn1Sequence)
-			{
-				return new EncryptedPrivateKeyInfo((Asn1Sequence) obj);
-			}
+			if (obj is Asn1Sequence seq)
+				return new EncryptedPrivateKeyInfo(seq);
 
 			throw new ArgumentException("Unknown object in factory: " + Platform.GetTypeName(obj), "obj");
 		}
diff --git a/crypto/src/asn1/pkcs/PBEParameter.cs b/crypto/src/asn1/pkcs/PBEParameter.cs
index 56cea5fb7..e8e7c5a82 100644
--- a/crypto/src/asn1/pkcs/PBEParameter.cs
+++ b/crypto/src/asn1/pkcs/PBEParameter.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Utilities;
diff --git a/crypto/src/asn1/pkcs/PrivateKeyInfo.cs b/crypto/src/asn1/pkcs/PrivateKeyInfo.cs
index d52a31f73..8d767c477 100644
--- a/crypto/src/asn1/pkcs/PrivateKeyInfo.cs
+++ b/crypto/src/asn1/pkcs/PrivateKeyInfo.cs
@@ -1,6 +1,4 @@
 using System;
-using System.Collections;
-using System.IO;
 
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Math;
@@ -108,7 +106,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs
 
         private PrivateKeyInfo(Asn1Sequence seq)
         {
-            IEnumerator e = seq.GetEnumerator();
+            var e = seq.GetEnumerator();
 
             this.version = DerInteger.GetInstance(CollectionUtilities.RequireNext(e));
 
diff --git a/crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs b/crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs
index 119ee98de..c445df562 100644
--- a/crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs
+++ b/crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs
@@ -1,7 +1,5 @@
 using System;
-using System.Collections;
 
-using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Math;
 
 namespace Org.BouncyCastle.Asn1.Pkcs
diff --git a/crypto/src/asn1/pkcs/SignedData.cs b/crypto/src/asn1/pkcs/SignedData.cs
index ae335103c..e309d9245 100644
--- a/crypto/src/asn1/pkcs/SignedData.cs
+++ b/crypto/src/asn1/pkcs/SignedData.cs
@@ -1,7 +1,4 @@
 using System;
-using System.Collections;
-
-using Org.BouncyCastle.Asn1;
 
 namespace Org.BouncyCastle.Asn1.Pkcs
 {
@@ -47,7 +44,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs
         private SignedData(
             Asn1Sequence seq)
         {
-            IEnumerator e = seq.GetEnumerator();
+            var e = seq.GetEnumerator();
 
             e.MoveNext();
             version = (DerInteger) e.Current;
@@ -60,26 +57,24 @@ namespace Org.BouncyCastle.Asn1.Pkcs
 
             while (e.MoveNext())
             {
-                Asn1Object o = (Asn1Object) e.Current;
+                Asn1Object o = e.Current.ToAsn1Object();
 
                 //
                 // an interesting feature of SignedData is that there appear to be varying implementations...
                 // for the moment we ignore anything which doesn't fit.
                 //
-                if (o is Asn1TaggedObject)
+                if (o is Asn1TaggedObject tagged)
                 {
-                    Asn1TaggedObject tagged = (Asn1TaggedObject)o;
-
                     switch (tagged.TagNo)
                     {
-                        case 0:
-                            certificates = Asn1Set.GetInstance(tagged, false);
-                            break;
-                        case 1:
-                            crls = Asn1Set.GetInstance(tagged, false);
-                            break;
-                        default:
-                            throw new ArgumentException("unknown tag value " + tagged.TagNo);
+                    case 0:
+                        certificates = Asn1Set.GetInstance(tagged, false);
+                        break;
+                    case 1:
+                        crls = Asn1Set.GetInstance(tagged, false);
+                        break;
+                    default:
+                        throw new ArgumentException("unknown tag value " + tagged.TagNo);
                     }
                 }
                 else
diff --git a/crypto/src/asn1/pkcs/SignerInfo.cs b/crypto/src/asn1/pkcs/SignerInfo.cs
index c594b45e9..7abd8e5c6 100644
--- a/crypto/src/asn1/pkcs/SignerInfo.cs
+++ b/crypto/src/asn1/pkcs/SignerInfo.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Utilities;
@@ -57,7 +56,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs
 		public SignerInfo(
             Asn1Sequence seq)
         {
-            IEnumerator e = seq.GetEnumerator();
+            var e = seq.GetEnumerator();
 
 			e.MoveNext();
             version = (DerInteger) e.Current;
@@ -69,11 +68,11 @@ namespace Org.BouncyCastle.Asn1.Pkcs
             digAlgorithm = AlgorithmIdentifier.GetInstance(e.Current);
 
 			e.MoveNext();
-            object obj = e.Current;
+            var obj = e.Current;
 
-			if (obj is Asn1TaggedObject)
+			if (obj is Asn1TaggedObject tagged)
             {
-                authenticatedAttributes = Asn1Set.GetInstance((Asn1TaggedObject) obj, false);
+                authenticatedAttributes = Asn1Set.GetInstance(tagged, false);
 
 				e.MoveNext();
                 digEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(e.Current);
diff --git a/crypto/src/asn1/smime/SMIMECapabilities.cs b/crypto/src/asn1/smime/SMIMECapabilities.cs
index 0bfa05034..0142f0797 100644
--- a/crypto/src/asn1/smime/SMIMECapabilities.cs
+++ b/crypto/src/asn1/smime/SMIMECapabilities.cs
@@ -1,7 +1,6 @@
 using System;
-using System.Collections;
+using System.Collections.Generic;
 
-using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Nist;
 using Org.BouncyCastle.Asn1.Pkcs;
 using Org.BouncyCastle.Asn1.X509;
@@ -76,35 +75,22 @@ namespace Org.BouncyCastle.Asn1.Smime
          * matching the passed in capability Oid. If the Oid passed is null the
          * entire set is returned.
          */
-        public IList GetCapabilitiesForOid(
-            DerObjectIdentifier capability)
+        public IList<SmimeCapability> GetCapabilitiesForOid(DerObjectIdentifier capability)
         {
-            IList list = Platform.CreateArrayList();
+            var list = new List<SmimeCapability>();
             DoGetCapabilitiesForOid(capability, list);
 			return list;
         }
 
-        private void DoGetCapabilitiesForOid(DerObjectIdentifier capability, IList list)
+        private void DoGetCapabilitiesForOid(DerObjectIdentifier capability, IList<SmimeCapability> list)
         {
-			if (capability == null)
+            foreach (object o in capabilities)
             {
-				foreach (object o in capabilities)
-				{
-                    SmimeCapability cap = SmimeCapability.GetInstance(o);
+                SmimeCapability cap = SmimeCapability.GetInstance(o);
 
-					list.Add(cap);
-                }
-            }
-            else
-            {
-				foreach (object o in capabilities)
-				{
-                    SmimeCapability cap = SmimeCapability.GetInstance(o);
-
-					if (capability.Equals(cap.CapabilityID))
-                    {
-                        list.Add(cap);
-                    }
+                if (capability == null || capability.Equals(cap.CapabilityID))
+                {
+                    list.Add(cap);
                 }
             }
         }
diff --git a/crypto/src/asn1/tsp/TSTInfo.cs b/crypto/src/asn1/tsp/TSTInfo.cs
index 3f5ab28bb..28a840e77 100644
--- a/crypto/src/asn1/tsp/TSTInfo.cs
+++ b/crypto/src/asn1/tsp/TSTInfo.cs
@@ -1,9 +1,6 @@
 using System;
-using System.Collections;
-using System.IO;
 
 using Org.BouncyCastle.Asn1.X509;
-using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.Tsp
 {
@@ -30,10 +27,9 @@ namespace Org.BouncyCastle.Asn1.Tsp
             return new TstInfo(Asn1Sequence.GetInstance(obj));
 		}
 
-		private TstInfo(
-			Asn1Sequence seq)
+		private TstInfo(Asn1Sequence seq)
 		{
-			IEnumerator e = seq.GetEnumerator();
+			var e = seq.GetEnumerator();
 
 			// version
 			e.MoveNext();
diff --git a/crypto/src/asn1/x500/style/IetfUtilities.cs b/crypto/src/asn1/x500/style/IetfUtilities.cs
index 53e5fccf4..e269f418d 100644
--- a/crypto/src/asn1/x500/style/IetfUtilities.cs
+++ b/crypto/src/asn1/x500/style/IetfUtilities.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 using System.IO;
 using System.Text;
 
diff --git a/crypto/src/asn1/x509/AttributeTable.cs b/crypto/src/asn1/x509/AttributeTable.cs
index 71c42872e..eeee88fd7 100644
--- a/crypto/src/asn1/x509/AttributeTable.cs
+++ b/crypto/src/asn1/x509/AttributeTable.cs
@@ -1,55 +1,50 @@
-using System;
-using System.Collections;
+using System.Collections.Generic;
 
-using Org.BouncyCastle.Utilities;
+using Org.BouncyCastle.Utilities.Collections;
 
 namespace Org.BouncyCastle.Asn1.X509
 {
     public class AttributeTable
     {
-        private readonly IDictionary attributes;
+        private readonly IDictionary<DerObjectIdentifier, AttributeX509> m_attributes;
 
-        public AttributeTable(
-            IDictionary attrs)
+        public AttributeTable(IDictionary<DerObjectIdentifier, AttributeX509> attrs)
         {
-            this.attributes = Platform.CreateHashtable(attrs);
+            m_attributes = new Dictionary<DerObjectIdentifier, AttributeX509>(attrs);
         }
 
-		public AttributeTable(
-            Asn1EncodableVector v)
+		public AttributeTable(Asn1EncodableVector v)
         {
-            this.attributes = Platform.CreateHashtable(v.Count);
+            m_attributes = new Dictionary<DerObjectIdentifier, AttributeX509>(v.Count);
 
-			for (int i = 0; i != v.Count; i++)
+            for (int i = 0; i != v.Count; i++)
             {
                 AttributeX509 a = AttributeX509.GetInstance(v[i]);
 
-				attributes.Add(a.AttrType, a);
+				m_attributes.Add(a.AttrType, a);
             }
         }
 
-		public AttributeTable(
-            Asn1Set s)
+		public AttributeTable(Asn1Set s)
         {
-            this.attributes = Platform.CreateHashtable(s.Count);
+            m_attributes = new Dictionary<DerObjectIdentifier, AttributeX509>(s.Count);
 
-			for (int i = 0; i != s.Count; i++)
+            for (int i = 0; i != s.Count; i++)
             {
                 AttributeX509 a = AttributeX509.GetInstance(s[i]);
 
-				attributes.Add(a.AttrType, a);
+				m_attributes.Add(a.AttrType, a);
             }
         }
 
-		public AttributeX509 Get(
-            DerObjectIdentifier oid)
+		public AttributeX509 Get(DerObjectIdentifier oid)
         {
-            return (AttributeX509) attributes[oid];
+            return CollectionUtilities.GetValueOrNull(m_attributes, oid);
         }
 
-        public IDictionary ToDictionary()
+        public IDictionary<DerObjectIdentifier, AttributeX509> ToDictionary()
         {
-            return Platform.CreateHashtable(attributes);
+            return new Dictionary<DerObjectIdentifier, AttributeX509>(m_attributes);
         }
     }
 }
diff --git a/crypto/src/asn1/x509/AuthorityInformationAccess.cs b/crypto/src/asn1/x509/AuthorityInformationAccess.cs
index f4b694cf0..57868baea 100644
--- a/crypto/src/asn1/x509/AuthorityInformationAccess.cs
+++ b/crypto/src/asn1/x509/AuthorityInformationAccess.cs
@@ -1,8 +1,6 @@
 using System;
-using System.Collections;
 using System.Text;
 
-using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.X509
diff --git a/crypto/src/asn1/x509/AuthorityKeyIdentifier.cs b/crypto/src/asn1/x509/AuthorityKeyIdentifier.cs
index e7f12016a..64cfce214 100644
--- a/crypto/src/asn1/x509/AuthorityKeyIdentifier.cs
+++ b/crypto/src/asn1/x509/AuthorityKeyIdentifier.cs
@@ -1,10 +1,8 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.Digests;
 using Org.BouncyCastle.Math;
-using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.Encoders;
 
 namespace Org.BouncyCastle.Asn1.X509
diff --git a/crypto/src/asn1/x509/CertificateList.cs b/crypto/src/asn1/x509/CertificateList.cs
index 567cf132a..3d5d2e557 100644
--- a/crypto/src/asn1/x509/CertificateList.cs
+++ b/crypto/src/asn1/x509/CertificateList.cs
@@ -1,7 +1,5 @@
 using System;
-using System.Collections;
-
-using Org.BouncyCastle.Asn1;
+using System.Collections.Generic;
 
 namespace Org.BouncyCastle.Asn1.X509
 {
@@ -65,7 +63,7 @@ namespace Org.BouncyCastle.Asn1.X509
             return tbsCertList.GetRevokedCertificates();
         }
 
-		public IEnumerable GetRevokedCertificateEnumeration()
+		public IEnumerable<CrlEntry> GetRevokedCertificateEnumeration()
 		{
 			return tbsCertList.GetRevokedCertificateEnumeration();
 		}
diff --git a/crypto/src/asn1/x509/DSAParameter.cs b/crypto/src/asn1/x509/DSAParameter.cs
index 2eb65024b..166ed9d08 100644
--- a/crypto/src/asn1/x509/DSAParameter.cs
+++ b/crypto/src/asn1/x509/DSAParameter.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Utilities;
diff --git a/crypto/src/asn1/x509/DigestInfo.cs b/crypto/src/asn1/x509/DigestInfo.cs
index 3ac535e2e..d9fceda32 100644
--- a/crypto/src/asn1/x509/DigestInfo.cs
+++ b/crypto/src/asn1/x509/DigestInfo.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Utilities;
 
diff --git a/crypto/src/asn1/x509/ExtendedKeyUsage.cs b/crypto/src/asn1/x509/ExtendedKeyUsage.cs
index 1e7d4d642..f812c308d 100644
--- a/crypto/src/asn1/x509/ExtendedKeyUsage.cs
+++ b/crypto/src/asn1/x509/ExtendedKeyUsage.cs
@@ -1,5 +1,5 @@
 using System;
-using System.Collections;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Utilities;
 
@@ -38,11 +38,10 @@ namespace Org.BouncyCastle.Asn1.X509
             return GetInstance(X509Extensions.GetExtensionParsedValue(extensions, X509Extensions.ExtendedKeyUsage));
         }
 
-        internal readonly IDictionary usageTable = Platform.CreateHashtable();
+        internal readonly ISet<DerObjectIdentifier> m_usageTable = new HashSet<DerObjectIdentifier>();
         internal readonly Asn1Sequence seq;
 
-        private ExtendedKeyUsage(
-            Asn1Sequence seq)
+        private ExtendedKeyUsage(Asn1Sequence seq)
         {
             this.seq = seq;
 
@@ -50,23 +49,21 @@ namespace Org.BouncyCastle.Asn1.X509
             {
                 DerObjectIdentifier oid = DerObjectIdentifier.GetInstance(element);
 
-                this.usageTable[oid] = oid;
+                m_usageTable.Add(oid);
             }
         }
 
-        public ExtendedKeyUsage(
-            params KeyPurposeID[] usages)
+        public ExtendedKeyUsage(params KeyPurposeID[] usages)
         {
             this.seq = new DerSequence(usages);
 
             foreach (KeyPurposeID usage in usages)
             {
-                this.usageTable[usage] = usage;
+                m_usageTable.Add(usage);
             }
         }
 
-        public ExtendedKeyUsage(
-            IEnumerable usages)
+        public ExtendedKeyUsage(IEnumerable<DerObjectIdentifier> usages)
         {
             Asn1EncodableVector v = new Asn1EncodableVector();
 
@@ -75,16 +72,15 @@ namespace Org.BouncyCastle.Asn1.X509
                 DerObjectIdentifier oid = DerObjectIdentifier.GetInstance(usage);
 
                 v.Add(oid);
-                this.usageTable[oid] = oid;
+                m_usageTable.Add(oid);
             }
 
             this.seq = new DerSequence(v);
         }
 
-        public bool HasKeyPurposeId(
-            KeyPurposeID keyPurposeId)
+        public bool HasKeyPurposeId(KeyPurposeID keyPurposeId)
         {
-            return usageTable.Contains(keyPurposeId);
+            return m_usageTable.Contains(keyPurposeId);
         }
 
         /**
@@ -92,14 +88,14 @@ namespace Org.BouncyCastle.Asn1.X509
          * The returned ArrayList contains DerObjectIdentifier instances.
          * @return An ArrayList with all key purposes.
          */
-        public IList GetAllUsages()
+        public IList<DerObjectIdentifier> GetAllUsages()
         {
-            return Platform.CreateArrayList(usageTable.Values);
+            return new List<DerObjectIdentifier>(m_usageTable);
         }
 
         public int Count
         {
-            get { return usageTable.Count; }
+            get { return m_usageTable.Count; }
         }
 
         public override Asn1Object ToAsn1Object()
diff --git a/crypto/src/asn1/x509/GeneralName.cs b/crypto/src/asn1/x509/GeneralName.cs
index 7b65e3239..c6c6e509e 100644
--- a/crypto/src/asn1/x509/GeneralName.cs
+++ b/crypto/src/asn1/x509/GeneralName.cs
@@ -1,5 +1,5 @@
 using System;
-using System.Collections;
+using System.Collections.Generic;
 using System.Globalization;
 using System.IO;
 using System.Text;
@@ -367,7 +367,8 @@ namespace Org.BouncyCastle.Asn1.X509
 				ip = ip.Substring(0, ip.Length - 1);
 			}
 
-			IEnumerator sEnum = ip.Split(':').GetEnumerator();
+			IEnumerable<string> split = ip.Split(':');
+			var sEnum = split.GetEnumerator();
 
 			int index = 0;
 			int[] val = new int[8];
@@ -376,7 +377,7 @@ namespace Org.BouncyCastle.Asn1.X509
 
 			while (sEnum.MoveNext())
 			{
-				string e = (string) sEnum.Current;
+				string e = sEnum.Current;
 
 				if (e.Length == 0)
 				{
diff --git a/crypto/src/asn1/x509/IetfAttrSyntax.cs b/crypto/src/asn1/x509/IetfAttrSyntax.cs
index 05313b1af..61fe78561 100644
--- a/crypto/src/asn1/x509/IetfAttrSyntax.cs
+++ b/crypto/src/asn1/x509/IetfAttrSyntax.cs
@@ -1,7 +1,4 @@
 using System;
-using System.Collections;
-
-using Org.BouncyCastle.Asn1;
 
 namespace Org.BouncyCastle.Asn1.X509
 {
diff --git a/crypto/src/asn1/x509/NameConstraints.cs b/crypto/src/asn1/x509/NameConstraints.cs
index 40178c126..9fe4fdd01 100644
--- a/crypto/src/asn1/x509/NameConstraints.cs
+++ b/crypto/src/asn1/x509/NameConstraints.cs
@@ -1,5 +1,5 @@
 using System;
-using System.Collections;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Utilities;
 
@@ -43,15 +43,6 @@ namespace Org.BouncyCastle.Asn1.X509
 			}
 		}
 
-#if !PORTABLE
-        public NameConstraints(
-            ArrayList permitted,
-            ArrayList excluded)
-            : this((IList)permitted, (IList)excluded)
-        {
-        }
-#endif
-
         /**
 		 * Constructor from a given details.
 		 *
@@ -61,8 +52,8 @@ namespace Org.BouncyCastle.Asn1.X509
 		 * @param excluded Excluded subtrees
 		 */
 		public NameConstraints(
-			IList   permitted,
-			IList   excluded)
+			IList<GeneralSubtree> permitted,
+			IList<GeneralSubtree> excluded)
 		{
 			if (permitted != null)
 			{
@@ -75,13 +66,12 @@ namespace Org.BouncyCastle.Asn1.X509
 			}
 		}
 
-		private DerSequence CreateSequence(
-			IList subtrees)
+		private DerSequence CreateSequence(IList<GeneralSubtree> subtrees)
 		{
             GeneralSubtree[] gsts = new GeneralSubtree[subtrees.Count];
             for (int i = 0; i < subtrees.Count; ++i)
             {
-                gsts[i] = (GeneralSubtree)subtrees[i];
+                gsts[i] = subtrees[i];
             }
             return new DerSequence(gsts);
 		}
diff --git a/crypto/src/asn1/x509/NoticeReference.cs b/crypto/src/asn1/x509/NoticeReference.cs
index f0d3a7b7f..98a64ec55 100644
--- a/crypto/src/asn1/x509/NoticeReference.cs
+++ b/crypto/src/asn1/x509/NoticeReference.cs
@@ -1,5 +1,5 @@
 using System;
-using System.Collections;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Math;
 
@@ -26,7 +26,7 @@ namespace Org.BouncyCastle.Asn1.X509
         private readonly DisplayText organization;
         private readonly Asn1Sequence noticeNumbers;
 
-        private static Asn1EncodableVector ConvertVector(IList numbers)
+        private static Asn1EncodableVector ConvertVector(IList<object> numbers)
         {
             Asn1EncodableVector av = new Asn1EncodableVector();
 
@@ -58,7 +58,7 @@ namespace Org.BouncyCastle.Asn1.X509
          * @param organization a <code>String</code> value
          * @param numbers a <code>Vector</code> value
          */
-        public NoticeReference(string organization, IList numbers)
+        public NoticeReference(string organization, IList<object> numbers)
             : this(organization, ConvertVector(numbers))
         {
         }
diff --git a/crypto/src/asn1/x509/PolicyMappings.cs b/crypto/src/asn1/x509/PolicyMappings.cs
index 8c9f97814..a077f2059 100644
--- a/crypto/src/asn1/x509/PolicyMappings.cs
+++ b/crypto/src/asn1/x509/PolicyMappings.cs
@@ -1,4 +1,4 @@
-using System.Collections;
+using System.Collections.Generic;
 
 namespace Org.BouncyCastle.Asn1.X509
 {
@@ -29,14 +29,6 @@ namespace Org.BouncyCastle.Asn1.X509
 			this.seq = seq;
 		}
 
-#if !PORTABLE
-        public PolicyMappings(
-            Hashtable mappings)
-            : this((IDictionary)mappings)
-        {
-        }
-#endif
-
         /**
 		 * Creates a new <code>PolicyMappings</code> instance.
 		 *
@@ -44,14 +36,14 @@ namespace Org.BouncyCastle.Asn1.X509
 		 * <code>string</code> oids
 		 * to other <code>string</code> oids.
 		 */
-		public PolicyMappings(
-			IDictionary mappings)
+		public PolicyMappings(IDictionary<string, string> mappings)
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector();
 
-			foreach (string idp in mappings.Keys)
+			foreach (var entry in mappings)
 			{
-				string sdp = (string) mappings[idp];
+				string idp = entry.Key;
+				string sdp = entry.Value;
 
 				v.Add(
 					new DerSequence(
diff --git a/crypto/src/asn1/x509/RSAPublicKeyStructure.cs b/crypto/src/asn1/x509/RSAPublicKeyStructure.cs
index 20fdd96ac..cdb02946a 100644
--- a/crypto/src/asn1/x509/RSAPublicKeyStructure.cs
+++ b/crypto/src/asn1/x509/RSAPublicKeyStructure.cs
@@ -1,7 +1,5 @@
 using System;
-using System.Collections;
 
-using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Utilities;
 
diff --git a/crypto/src/asn1/x509/SubjectDirectoryAttributes.cs b/crypto/src/asn1/x509/SubjectDirectoryAttributes.cs
index 00db90042..6ebd35e21 100644
--- a/crypto/src/asn1/x509/SubjectDirectoryAttributes.cs
+++ b/crypto/src/asn1/x509/SubjectDirectoryAttributes.cs
@@ -1,5 +1,5 @@
 using System;
-using System.Collections;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.Collections;
@@ -28,7 +28,7 @@ namespace Org.BouncyCastle.Asn1.X509
 	public class SubjectDirectoryAttributes
 		: Asn1Encodable
 	{
-		private readonly IList attributes;
+		private readonly IList<AttributeX509> m_attributes;
 
 		public static SubjectDirectoryAttributes GetInstance(
 			object obj)
@@ -70,11 +70,12 @@ namespace Org.BouncyCastle.Asn1.X509
 		private SubjectDirectoryAttributes(
 			Asn1Sequence seq)
 		{
-            this.attributes = Platform.CreateArrayList();
+            m_attributes = new List<AttributeX509>();
+
             foreach (object o in seq)
 			{
 				Asn1Sequence s = Asn1Sequence.GetInstance(o);
-				attributes.Add(AttributeX509.GetInstance(s));
+				m_attributes.Add(AttributeX509.GetInstance(s));
 			}
 		}
 
@@ -86,11 +87,10 @@ namespace Org.BouncyCastle.Asn1.X509
 		 * @param attributes The attributes.
 		 *
 		 */
-		public SubjectDirectoryAttributes(
-			IList attributes)
+		public SubjectDirectoryAttributes(IList<AttributeX509> attributes)
 		{
-            this.attributes = Platform.CreateArrayList(attributes);
-        }
+			m_attributes = new List<AttributeX509>(attributes);
+		}
 
 		/**
 		 * Produce an object suitable for an Asn1OutputStream.
@@ -114,10 +114,10 @@ namespace Org.BouncyCastle.Asn1.X509
 		 */
 		public override Asn1Object ToAsn1Object()
 		{
-            AttributeX509[] v = new AttributeX509[attributes.Count];
-            for (int i = 0; i < attributes.Count; ++i)
+            AttributeX509[] v = new AttributeX509[m_attributes.Count];
+            for (int i = 0; i < m_attributes.Count; ++i)
             {
-                v[i] = (AttributeX509)attributes[i];
+                v[i] = m_attributes[i];
             }
             return new DerSequence(v);
 		}
@@ -125,9 +125,9 @@ namespace Org.BouncyCastle.Asn1.X509
         /**
 		 * @return Returns the attributes.
 		 */
-		public IEnumerable Attributes
+		public IEnumerable<AttributeX509> Attributes
 		{
-			get { return new EnumerableProxy(attributes); }
+			get { return CollectionUtilities.Proxy(m_attributes); }
 		}
 	}
 }
diff --git a/crypto/src/asn1/x509/SubjectPublicKeyInfo.cs b/crypto/src/asn1/x509/SubjectPublicKeyInfo.cs
index 474493dcf..52f977e91 100644
--- a/crypto/src/asn1/x509/SubjectPublicKeyInfo.cs
+++ b/crypto/src/asn1/x509/SubjectPublicKeyInfo.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 using System.IO;
 
 namespace Org.BouncyCastle.Asn1.X509
diff --git a/crypto/src/asn1/x509/TBSCertList.cs b/crypto/src/asn1/x509/TBSCertList.cs
index a427ba2ba..aef41d440 100644
--- a/crypto/src/asn1/x509/TBSCertList.cs
+++ b/crypto/src/asn1/x509/TBSCertList.cs
@@ -1,8 +1,7 @@
 using System;
-using System.Collections;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Utilities;
-using Org.BouncyCastle.Utilities.Collections;
 
 namespace Org.BouncyCastle.Asn1.X509
 {
@@ -14,13 +13,10 @@ namespace Org.BouncyCastle.Asn1.X509
 		internal Time			revocationDate;
 		internal X509Extensions	crlEntryExtensions;
 
-		public CrlEntry(
-			Asn1Sequence seq)
+		public CrlEntry(Asn1Sequence seq)
 		{
 			if (seq.Count < 2 || seq.Count > 3)
-			{
 				throw new ArgumentException("Bad sequence size: " + seq.Count);
-			}
 
 			this.seq = seq;
 
@@ -82,32 +78,39 @@ namespace Org.BouncyCastle.Asn1.X509
         : Asn1Encodable
     {
 		private class RevokedCertificatesEnumeration
-			: IEnumerable
+			: IEnumerable<CrlEntry>
 		{
-			private readonly IEnumerable en;
+			private readonly IEnumerable<Asn1Encodable> en;
 
-			internal RevokedCertificatesEnumeration(
-				IEnumerable en)
+			internal RevokedCertificatesEnumeration(IEnumerable<Asn1Encodable> en)
 			{
 				this.en = en;
 			}
 
-			public IEnumerator GetEnumerator()
+			System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+            {
+				return GetEnumerator();
+            }
+
+			public IEnumerator<CrlEntry> GetEnumerator()
 			{
 				return new RevokedCertificatesEnumerator(en.GetEnumerator());
 			}
 
 			private class RevokedCertificatesEnumerator
-				: IEnumerator
+				: IEnumerator<CrlEntry>
 			{
-				private readonly IEnumerator e;
+				private readonly IEnumerator<Asn1Encodable> e;
 
-				internal RevokedCertificatesEnumerator(
-					IEnumerator e)
+				internal RevokedCertificatesEnumerator(IEnumerator<Asn1Encodable> e)
 				{
 					this.e = e;
 				}
 
+				public virtual void Dispose()
+				{
+				}
+
 				public bool MoveNext()
 				{
 					return e.MoveNext();
@@ -118,7 +121,12 @@ namespace Org.BouncyCastle.Asn1.X509
 					e.Reset();
 				}
 
-				public object Current
+				object System.Collections.IEnumerator.Current
+                {
+					get { return Current; }
+                }
+
+				public CrlEntry Current
 				{
 					get { return new CrlEntry(Asn1Sequence.GetInstance(e.Current)); }
 				}
@@ -252,11 +260,13 @@ namespace Org.BouncyCastle.Asn1.X509
 			return entries;
 		}
 
-		public IEnumerable GetRevokedCertificateEnumeration()
+		public IEnumerable<CrlEntry> GetRevokedCertificateEnumeration()
 		{
 			if (revokedCertificates == null)
 			{
-				return EmptyEnumerable.Instance;
+				// TODO
+				//return EmptyEnumerable.Instance;
+				return new List<CrlEntry>(0);
 			}
 
 			return new RevokedCertificatesEnumeration(revokedCertificates);
diff --git a/crypto/src/asn1/x509/X509ExtensionsGenerator.cs b/crypto/src/asn1/x509/X509ExtensionsGenerator.cs
index 438c507aa..53d18ecff 100644
--- a/crypto/src/asn1/x509/X509ExtensionsGenerator.cs
+++ b/crypto/src/asn1/x509/X509ExtensionsGenerator.cs
@@ -1,9 +1,6 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
 
-using Org.BouncyCastle.Utilities;
-
 namespace Org.BouncyCastle.Asn1.X509
 {
     /// <remarks>Generator for X.509 extensions</remarks>
@@ -13,15 +10,13 @@ namespace Org.BouncyCastle.Asn1.X509
             new Dictionary<DerObjectIdentifier, X509Extension>();
         private List<DerObjectIdentifier> m_ordering = new List<DerObjectIdentifier>();
 
-        private static readonly IDictionary dupsAllowed = Platform.CreateHashtable();
-
-        static X509ExtensionsGenerator()
+        private static readonly ISet<DerObjectIdentifier> m_dupsAllowed = new HashSet<DerObjectIdentifier>()
         {
-            dupsAllowed.Add(X509Extensions.SubjectAlternativeName, true);
-            dupsAllowed.Add(X509Extensions.IssuerAlternativeName, true);
-            dupsAllowed.Add(X509Extensions.SubjectDirectoryAttributes, true);
-            dupsAllowed.Add(X509Extensions.CertificateIssuer, true);
-        }
+            X509Extensions.SubjectAlternativeName,
+            X509Extensions.IssuerAlternativeName,
+            X509Extensions.SubjectDirectoryAttributes,
+            X509Extensions.CertificateIssuer
+        };
 
         /// <summary>Reset the generator</summary>
         public void Reset()
@@ -63,7 +58,7 @@ namespace Org.BouncyCastle.Asn1.X509
         {
             if (m_extensions.TryGetValue(oid, out X509Extension existingExtension))
             {
-                if (!dupsAllowed.Contains(oid))
+                if (!m_dupsAllowed.Contains(oid))
                     throw new ArgumentException("extension " + oid + " already added");
 
                 Asn1Sequence seq1 = Asn1Sequence.GetInstance(
diff --git a/crypto/src/asn1/x509/X509Name.cs b/crypto/src/asn1/x509/X509Name.cs
index 0683b380c..7c9797e56 100644
--- a/crypto/src/asn1/x509/X509Name.cs
+++ b/crypto/src/asn1/x509/X509Name.cs
@@ -1,11 +1,9 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 using System.Text;
 
 using Org.BouncyCastle.Asn1.Pkcs;
-using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.Encoders;
 
 namespace Org.BouncyCastle.Asn1.X509
@@ -205,51 +203,31 @@ namespace Org.BouncyCastle.Asn1.X509
 
         private static readonly bool[] defaultReverse = { false };
 
-#if PORTABLE
         /**
         * default look up table translating OID values into their common symbols following
         * the convention in RFC 2253 with a few extras
         */
-        public static readonly IDictionary DefaultSymbols = Platform.CreateHashtable();
+        public static readonly IDictionary<DerObjectIdentifier, string> DefaultSymbols =
+            new Dictionary<DerObjectIdentifier, string>();
 
         /**
          * look up table translating OID values into their common symbols following the convention in RFC 2253
          */
-        public static readonly IDictionary RFC2253Symbols = Platform.CreateHashtable();
+        public static readonly IDictionary<DerObjectIdentifier, string> RFC2253Symbols =
+            new Dictionary<DerObjectIdentifier, string>();
 
         /**
          * look up table translating OID values into their common symbols following the convention in RFC 1779
          *
          */
-        public static readonly IDictionary RFC1779Symbols = Platform.CreateHashtable();
+        public static readonly IDictionary<DerObjectIdentifier, string> RFC1779Symbols =
+            new Dictionary<DerObjectIdentifier, string>();
 
         /**
         * look up table translating common symbols into their OIDS.
         */
-        public static readonly IDictionary DefaultLookup = Platform.CreateHashtable();
-#else
-        /**
-        * default look up table translating OID values into their common symbols following
-        * the convention in RFC 2253 with a few extras
-        */
-        public static readonly Hashtable DefaultSymbols = new Hashtable();
-
-        /**
-         * look up table translating OID values into their common symbols following the convention in RFC 2253
-         */
-        public static readonly Hashtable RFC2253Symbols = new Hashtable();
-
-        /**
-         * look up table translating OID values into their common symbols following the convention in RFC 1779
-         *
-         */
-        public static readonly Hashtable RFC1779Symbols = new Hashtable();
-
-        /**
-        * look up table translating common symbols into their OIDS.
-        */
-        public static readonly Hashtable DefaultLookup = new Hashtable();
-#endif
+        public static readonly IDictionary<string, DerObjectIdentifier> DefaultLookup =
+            new Dictionary<string, DerObjectIdentifier>(StringComparer.OrdinalIgnoreCase);
 
         static X509Name()
         {
@@ -340,9 +318,9 @@ namespace Org.BouncyCastle.Asn1.X509
         private readonly List<DerObjectIdentifier> ordering = new List<DerObjectIdentifier>();
         private readonly X509NameEntryConverter converter;
 
-        private IList		    values = Platform.CreateArrayList();
-        private IList           added = Platform.CreateArrayList();
-        private Asn1Sequence	seq;
+        private IList<string> values = new List<string>();
+        private IList<bool> added = new List<bool>();
+        private Asn1Sequence seq;
 
         /**
         * Return a X509Name based on the passed in tagged object.
@@ -377,8 +355,7 @@ namespace Org.BouncyCastle.Asn1.X509
         *
         * the principal will be a list of constructed sets, each containing an (OID, string) pair.
         */
-        protected X509Name(
-            Asn1Sequence seq)
+        protected X509Name(Asn1Sequence seq)
         {
             this.seq = seq;
 
@@ -399,7 +376,7 @@ namespace Org.BouncyCastle.Asn1.X509
                     if (derValue is IAsn1String && !(derValue is DerUniversalString))
                     {
                         string v = ((IAsn1String)derValue).GetString();
-                        if (Platform.StartsWith(v, "#"))
+                        if (v.StartsWith("#"))
                         {
                             v = "\\" + v;
                         }
@@ -425,8 +402,8 @@ namespace Org.BouncyCastle.Asn1.X509
         * in the order they are meant to be encoded or printed in ToString.</p>
         */
         public X509Name(
-            IList       ordering,
-            IDictionary attributes)
+            IList<DerObjectIdentifier> ordering,
+            IDictionary<DerObjectIdentifier, string> attributes)
             : this(ordering, attributes, new X509DefaultEntryConverter())
         {
         }
@@ -443,19 +420,22 @@ namespace Org.BouncyCastle.Asn1.X509
         * ASN.1 counterparts.</p>
         */
         public X509Name(
-            IList                   ordering,
-            IDictionary             attributes,
+            IList<DerObjectIdentifier> ordering,
+            IDictionary<DerObjectIdentifier, string> attributes,
             X509NameEntryConverter	converter)
         {
             this.converter = converter;
 
             foreach (DerObjectIdentifier oid in ordering)
             {
-                object attribute = attributes[oid];
-                if (attribute == null)
-                {
+                if (!attributes.TryGetValue(oid, out var attribute))
                     throw new ArgumentException("No attribute for object id - " + oid + " - passed to distinguished name");
-                }
+
+                //object attribute = attributes[oid];
+                //if (attribute == null)
+                //{
+                //    throw new ArgumentException("No attribute for object id - " + oid + " - passed to distinguished name");
+                //}
 
                 this.ordering.Add(oid);
                 this.added.Add(false);
@@ -466,7 +446,7 @@ namespace Org.BouncyCastle.Asn1.X509
         /**
         * Takes two vectors one of the oids and the other of the values.
         */
-        public X509Name(IList<DerObjectIdentifier> oids, IList values)
+        public X509Name(IList<DerObjectIdentifier> oids, IList<string> values)
             : this(oids, values, new X509DefaultEntryConverter())
         {
         }
@@ -477,14 +457,12 @@ namespace Org.BouncyCastle.Asn1.X509
         * The passed in converter will be used to convert the strings into their
         * ASN.1 counterparts.</p>
         */
-        public X509Name(IList<DerObjectIdentifier> oids, IList values, X509NameEntryConverter converter)
+        public X509Name(IList<DerObjectIdentifier> oids, IList<string> values, X509NameEntryConverter converter)
         {
             this.converter = converter;
 
             if (oids.Count != values.Count)
-            {
                 throw new ArgumentException("'oids' must be same length as 'values'.");
-            }
 
             for (int i = 0; i < oids.Count; i++)
             {
@@ -499,7 +477,7 @@ namespace Org.BouncyCastle.Asn1.X509
         * some such, converting it into an ordered set of name attributes.
         */
         public X509Name(string dirName)
-            : this(DefaultReverse, (IDictionary)DefaultLookup, dirName)
+            : this(DefaultReverse, DefaultLookup, dirName)
         {
         }
 
@@ -509,9 +487,7 @@ namespace Org.BouncyCastle.Asn1.X509
         * string value being converted to its associated ASN.1 type using the passed
         * in converter.
         */
-        public X509Name(
-            string					dirName,
-            X509NameEntryConverter	converter)
+        public X509Name(string dirName, X509NameEntryConverter converter)
             : this(DefaultReverse, DefaultLookup, dirName, converter)
         {
         }
@@ -522,10 +498,8 @@ namespace Org.BouncyCastle.Asn1.X509
         * is true, create the encoded version of the sequence starting from the
         * last element in the string.
         */
-        public X509Name(
-            bool	reverse,
-            string	dirName)
-            : this(reverse, (IDictionary)DefaultLookup, dirName)
+        public X509Name(bool reverse, string dirName)
+            : this(reverse, DefaultLookup, dirName)
         {
         }
 
@@ -536,10 +510,7 @@ namespace Org.BouncyCastle.Asn1.X509
         * in converter. If reverse is true the ASN.1 sequence representing the DN will
         * be built by starting at the end of the string, rather than the start.
         */
-        public X509Name(
-            bool					reverse,
-            string					dirName,
-            X509NameEntryConverter	converter)
+        public X509Name(bool reverse, string dirName, X509NameEntryConverter converter)
             : this(reverse, DefaultLookup, dirName, converter)
         {
         }
@@ -557,34 +528,23 @@ namespace Org.BouncyCastle.Asn1.X509
         * @param lookUp table of names and their oids.
         * @param dirName the X.500 string to be parsed.
         */
-        public X509Name(
-            bool		reverse,
-            IDictionary lookUp,
-            string		dirName)
-            : this(reverse, lookUp, dirName, new X509DefaultEntryConverter())
+        public X509Name(bool reverse, IDictionary<string, DerObjectIdentifier> lookup, string dirName)
+            : this(reverse, lookup, dirName, new X509DefaultEntryConverter())
         {
         }
 
-        private DerObjectIdentifier DecodeOid(
-            string		name,
-            IDictionary lookUp)
+        private DerObjectIdentifier DecodeOid(string name, IDictionary<string, DerObjectIdentifier> lookup)
         {
-            if (Platform.StartsWith(Platform.ToUpperInvariant(name), "OID."))
-            {
-                return new DerObjectIdentifier(name.Substring(4));
-            }
-            else if (name[0] >= '0' && name[0] <= '9')
-            {
+            if (name.StartsWith("OID.", StringComparison.OrdinalIgnoreCase))
+                return new DerObjectIdentifier(name.Substring("OID.".Length));
+
+            if (name[0] >= '0' && name[0] <= '9')
                 return new DerObjectIdentifier(name);
-            }
 
-            DerObjectIdentifier oid = (DerObjectIdentifier)lookUp[Platform.ToLowerInvariant(name)];
-            if (oid == null)
-            {
-                throw new ArgumentException("Unknown object id - " + name + " - passed to distinguished name");
-            }
+            if (lookup.TryGetValue(name, out var oid))
+                return oid;
 
-            return oid;
+            throw new ArgumentException("Unknown object id - " + name + " - passed to distinguished name");
         }
 
         /**
@@ -600,11 +560,8 @@ namespace Org.BouncyCastle.Asn1.X509
         * @param dirName the string dirName
         * @param converter the converter to convert string values into their ASN.1 equivalents
         */
-        public X509Name(
-            bool					reverse,
-            IDictionary				lookUp,
-            string					dirName,
-            X509NameEntryConverter	converter)
+        public X509Name(bool reverse, IDictionary<string, DerObjectIdentifier> lookup, string dirName,
+            X509NameEntryConverter converter)
         {
             this.converter = converter;
             X509NameTokenizer nTok = new X509NameTokenizer(dirName);
@@ -615,13 +572,11 @@ namespace Org.BouncyCastle.Asn1.X509
                 int index = token.IndexOf('=');
 
                 if (index == -1)
-                {
                     throw new ArgumentException("badly formated directory string");
-                }
 
                 string name = token.Substring(0, index);
                 string value = token.Substring(index + 1);
-                DerObjectIdentifier	oid = DecodeOid(name, lookUp);
+                DerObjectIdentifier	oid = DecodeOid(name, lookup);
 
                 if (value.IndexOf('+') > 0)
                 {
@@ -639,7 +594,7 @@ namespace Org.BouncyCastle.Asn1.X509
 
                         string nm = sv.Substring(0, ndx);
                         string vl = sv.Substring(ndx + 1);
-                        this.ordering.Add(DecodeOid(nm, lookUp));
+                        this.ordering.Add(DecodeOid(nm, lookup));
                         this.values.Add(vl);
                         this.added.Add(true);
                     }
@@ -658,8 +613,8 @@ namespace Org.BouncyCastle.Asn1.X509
 //				this.values.Reverse();
 //				this.added.Reverse();
                 var o = new List<DerObjectIdentifier>();
-                IList v = Platform.CreateArrayList();
-                IList a = Platform.CreateArrayList();
+                var v = new List<string>();
+                var a = new List<bool>();
                 int count = 1;
 
                 for (int i = 0; i < this.ordering.Count; i++)
@@ -711,8 +666,7 @@ namespace Org.BouncyCastle.Asn1.X509
                 if (null == oid || oid.Equals(ordering[i]))
                 {
                     string val = (string)values[i];
-
-                    if (Platform.StartsWith(val, "\\#"))
+                    if (val.StartsWith("\\#"))
                     {
                         val = val.Substring(1);
                     }
@@ -794,7 +748,7 @@ namespace Org.BouncyCastle.Asn1.X509
                 string val = (string) values[i];
                 string oVal = (string) other.values[i];
 
-                if (!equivalentStrings(val, oVal))
+                if (!EquivalentStrings(val, oVal))
                     return false;
             }
 
@@ -855,7 +809,7 @@ namespace Org.BouncyCastle.Asn1.X509
                     {
                         string oValue = (string)other.values[j];
 
-                        if (equivalentStrings(value, oValue))
+                        if (EquivalentStrings(value, oValue))
                         {
                             indexes[j] = true;
                             found      = true;
@@ -873,47 +827,40 @@ namespace Org.BouncyCastle.Asn1.X509
             return true;
         }
 
-        private static bool equivalentStrings(
-            string	s1,
-            string	s2)
+        private static bool EquivalentStrings(string s1, string s2)
         {
-            string v1 = canonicalize(s1);
-            string v2 = canonicalize(s2);
+            string v1 = Canonicalize(s1);
+            string v2 = Canonicalize(s2);
 
             if (!v1.Equals(v2))
             {
-                v1 = stripInternalSpaces(v1);
-                v2 = stripInternalSpaces(v2);
+                v1 = StripInternalSpaces(v1);
+                v2 = StripInternalSpaces(v2);
 
                 if (!v1.Equals(v2))
-                {
                     return false;
-                }
             }
 
             return true;
         }
 
-        private static string canonicalize(
-            string s)
+        private static string Canonicalize(string s)
         {
-            string v = Platform.ToLowerInvariant(s).Trim();
+            string v = s.ToLowerInvariant().Trim();
 
-            if (Platform.StartsWith(v, "#"))
+            if (v.StartsWith("#"))
             {
-                Asn1Object obj = decodeObject(v);
-
-                if (obj is IAsn1String)
+                Asn1Object obj = DecodeObject(v);
+                if (obj is IAsn1String str)
                 {
-                    v = Platform.ToLowerInvariant(((IAsn1String)obj).GetString()).Trim();
+                    v = str.GetString().ToLowerInvariant().Trim();
                 }
             }
 
             return v;
         }
 
-        private static Asn1Object decodeObject(
-            string v)
+        private static Asn1Object DecodeObject(string v)
         {
             try
             {
@@ -925,8 +872,7 @@ namespace Org.BouncyCastle.Asn1.X509
             }
         }
 
-        private static string stripInternalSpaces(
-            string str)
+        private static string StripInternalSpaces(string str)
         {
             StringBuilder res = new StringBuilder();
 
@@ -950,15 +896,10 @@ namespace Org.BouncyCastle.Asn1.X509
             return res.ToString();
         }
 
-        private void AppendValue(
-            StringBuilder		buf,
-            IDictionary         oidSymbols,
-            DerObjectIdentifier	oid,
-            string				val)
+        private void AppendValue(StringBuilder buf, IDictionary<DerObjectIdentifier, string> oidSymbols,
+            DerObjectIdentifier oid, string val)
         {
-            string sym = (string)oidSymbols[oid];
-
-            if (sym != null)
+            if (oidSymbols.TryGetValue(oid, out var sym))
             {
                 buf.Append(sym);
             }
@@ -975,7 +916,7 @@ namespace Org.BouncyCastle.Asn1.X509
 
             int end = buf.Length;
 
-            if (Platform.StartsWith(val, "\\#"))
+            if (val.StartsWith("\\#"))
             {
                 index += 2;
             }
@@ -1011,33 +952,23 @@ namespace Org.BouncyCastle.Asn1.X509
         * @param reverse if true start at the end of the sequence and work back.
         * @param oidSymbols look up table strings for oids.
         */
-        public string ToString(
-            bool		reverse,
-            IDictionary oidSymbols)
+        public string ToString(bool reverse, IDictionary<DerObjectIdentifier, string> oidSymbols)
         {
-#if PORTABLE
-            List<object> components = new List<object>();
-#else
-            ArrayList components = new ArrayList();
-#endif
+            var components = new List<StringBuilder>();
 
             StringBuilder ava = null;
 
             for (int i = 0; i < ordering.Count; i++)
             {
-                if ((bool) added[i])
+                if (added[i])
                 {
                     ava.Append('+');
-                    AppendValue(ava, oidSymbols,
-                        (DerObjectIdentifier)ordering[i],
-                        (string)values[i]);
+                    AppendValue(ava, oidSymbols, ordering[i], values[i]);
                 }
                 else
                 {
                     ava = new StringBuilder();
-                    AppendValue(ava, oidSymbols,
-                        (DerObjectIdentifier)ordering[i],
-                        (string)values[i]);
+                    AppendValue(ava, oidSymbols, ordering[i], values[i]);
                     components.Add(ava);
                 }
             }
@@ -1065,7 +996,7 @@ namespace Org.BouncyCastle.Asn1.X509
 
         public override string ToString()
         {
-            return ToString(DefaultReverse, (IDictionary)DefaultSymbols);
+            return ToString(DefaultReverse, DefaultSymbols);
         }
     }
 }
diff --git a/crypto/src/asn1/x509/qualified/MonetaryValue.cs b/crypto/src/asn1/x509/qualified/MonetaryValue.cs
index d703de943..be4cd1142 100644
--- a/crypto/src/asn1/x509/qualified/MonetaryValue.cs
+++ b/crypto/src/asn1/x509/qualified/MonetaryValue.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Utilities;
diff --git a/crypto/src/asn1/x509/qualified/SemanticsInformation.cs b/crypto/src/asn1/x509/qualified/SemanticsInformation.cs
index 379e6d1d1..23818e916 100644
--- a/crypto/src/asn1/x509/qualified/SemanticsInformation.cs
+++ b/crypto/src/asn1/x509/qualified/SemanticsInformation.cs
@@ -1,7 +1,5 @@
 using System;
-using System.Collections;
 
-using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.X509.Qualified
@@ -42,33 +40,30 @@ namespace Org.BouncyCastle.Asn1.X509.Qualified
 			throw new ArgumentException("unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
 		}
 
-		public SemanticsInformation(
-			Asn1Sequence seq)
+		public SemanticsInformation(Asn1Sequence seq)
         {
             if (seq.Count < 1)
-            {
                 throw new ArgumentException("no objects in SemanticsInformation");
-            }
 
-			IEnumerator e = seq.GetEnumerator();
+			var e = seq.GetEnumerator();
 			e.MoveNext();
-            object obj = e.Current;
-            if (obj is DerObjectIdentifier)
+            var obj = e.Current;
+            if (obj is DerObjectIdentifier oid)
             {
-                semanticsIdentifier = DerObjectIdentifier.GetInstance(obj);
+                semanticsIdentifier = oid;
                 if (e.MoveNext())
                 {
-                    obj  = e.Current;
+                    obj = e.Current;
                 }
                 else
                 {
-                    obj  = null;
+                    obj = null;
                 }
             }
 
-			if (obj  != null)
+			if (obj != null)
             {
-                Asn1Sequence generalNameSeq = Asn1Sequence.GetInstance(obj );
+                Asn1Sequence generalNameSeq = Asn1Sequence.GetInstance(obj);
                 nameRegistrationAuthorities = new GeneralName[generalNameSeq.Count];
                 for (int i= 0; i < generalNameSeq.Count; i++)
                 {
@@ -97,7 +92,10 @@ namespace Org.BouncyCastle.Asn1.X509.Qualified
             this.nameRegistrationAuthorities = generalNames;
         }
 
-		public DerObjectIdentifier SemanticsIdentifier { get { return semanticsIdentifier; } }
+		public DerObjectIdentifier SemanticsIdentifier 
+        {
+            get { return semanticsIdentifier; }
+        }
 
 		public GeneralName[] GetNameRegistrationAuthorities()
         {
diff --git a/crypto/src/asn1/x509/sigi/NameOrPseudonym.cs b/crypto/src/asn1/x509/sigi/NameOrPseudonym.cs
index 2402e3832..c801002d1 100644
--- a/crypto/src/asn1/x509/sigi/NameOrPseudonym.cs
+++ b/crypto/src/asn1/x509/sigi/NameOrPseudonym.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Asn1.X500;
 using Org.BouncyCastle.Utilities;
diff --git a/crypto/src/asn1/x509/sigi/PersonalData.cs b/crypto/src/asn1/x509/sigi/PersonalData.cs
index 0e0bb5365..439039888 100644
--- a/crypto/src/asn1/x509/sigi/PersonalData.cs
+++ b/crypto/src/asn1/x509/sigi/PersonalData.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 
 using Org.BouncyCastle.Asn1.X500;
 using Org.BouncyCastle.Math;
@@ -69,13 +68,12 @@ namespace Org.BouncyCastle.Asn1.X509.SigI
 		*
 		* @param seq The ASN.1 sequence.
 		*/
-		private PersonalData(
-			Asn1Sequence seq)
+		private PersonalData(Asn1Sequence seq)
 		{
 			if (seq.Count < 1)
 				throw new ArgumentException("Bad sequence size: " + seq.Count);
 
-			IEnumerator e = seq.GetEnumerator();
+			var e = seq.GetEnumerator();
 			e.MoveNext();
 
 			nameOrPseudonym = NameOrPseudonym.GetInstance(e.Current);
@@ -86,23 +84,23 @@ namespace Org.BouncyCastle.Asn1.X509.SigI
 				int tag = o.TagNo;
 				switch (tag)
 				{
-					case 0:
-						nameDistinguisher = DerInteger.GetInstance(o, false).Value;
-						break;
-					case 1:
-						dateOfBirth = DerGeneralizedTime.GetInstance(o, false);
-						break;
-					case 2:
-						placeOfBirth = DirectoryString.GetInstance(o, true);
-						break;
-					case 3:
-						gender = DerPrintableString.GetInstance(o, false).GetString();
-						break;
-					case 4:
-						postalAddress = DirectoryString.GetInstance(o, true);
-						break;
-					default:
-						throw new ArgumentException("Bad tag number: " + o.TagNo);
+				case 0:
+					nameDistinguisher = DerInteger.GetInstance(o, false).Value;
+					break;
+				case 1:
+					dateOfBirth = DerGeneralizedTime.GetInstance(o, false);
+					break;
+				case 2:
+					placeOfBirth = DirectoryString.GetInstance(o, true);
+					break;
+				case 3:
+					gender = DerPrintableString.GetInstance(o, false).GetString();
+					break;
+				case 4:
+					postalAddress = DirectoryString.GetInstance(o, true);
+					break;
+				default:
+					throw new ArgumentException("Bad tag number: " + o.TagNo);
 				}
 			}
 		}
diff --git a/crypto/src/asn1/x9/DHDomainParameters.cs b/crypto/src/asn1/x9/DHDomainParameters.cs
index a92322717..0439b28cd 100644
--- a/crypto/src/asn1/x9/DHDomainParameters.cs
+++ b/crypto/src/asn1/x9/DHDomainParameters.cs
@@ -1,5 +1,5 @@
 using System;
-using System.Collections;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Utilities;
 
@@ -49,7 +49,7 @@ namespace Org.BouncyCastle.Asn1.X9
 			if (seq.Count < 3 || seq.Count > 5)
 				throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
 
-			IEnumerator e = seq.GetEnumerator();
+			var e = seq.GetEnumerator();
 			this.p = DerInteger.GetInstance(GetNext(e));
 			this.g = DerInteger.GetInstance(GetNext(e));
 			this.q = DerInteger.GetInstance(GetNext(e));
@@ -68,7 +68,7 @@ namespace Org.BouncyCastle.Asn1.X9
 			}
 		}
 
-		private static Asn1Encodable GetNext(IEnumerator e)
+		private static Asn1Encodable GetNext(IEnumerator<Asn1Encodable> e)
 		{
 			return e.MoveNext() ? (Asn1Encodable)e.Current : null;
 		}
diff --git a/crypto/src/asn1/x9/KeySpecificInfo.cs b/crypto/src/asn1/x9/KeySpecificInfo.cs
index 46298646b..8e5fb9ea7 100644
--- a/crypto/src/asn1/x9/KeySpecificInfo.cs
+++ b/crypto/src/asn1/x9/KeySpecificInfo.cs
@@ -1,5 +1,3 @@
-using System.Collections;
-
 namespace Org.BouncyCastle.Asn1.X9
 {
     /**
@@ -20,10 +18,9 @@ namespace Org.BouncyCastle.Asn1.X9
             this.counter = counter;
         }
 
-		public KeySpecificInfo(
-            Asn1Sequence seq)
+		public KeySpecificInfo(Asn1Sequence seq)
         {
-            IEnumerator e = seq.GetEnumerator();
+            var e = seq.GetEnumerator();
 
 			e.MoveNext();
             algorithm = (DerObjectIdentifier)e.Current;
diff --git a/crypto/src/asn1/x9/OtherInfo.cs b/crypto/src/asn1/x9/OtherInfo.cs
index 4a52b7206..c1819a5ee 100644
--- a/crypto/src/asn1/x9/OtherInfo.cs
+++ b/crypto/src/asn1/x9/OtherInfo.cs
@@ -1,5 +1,3 @@
-using System.Collections;
-
 namespace Org.BouncyCastle.Asn1.X9
 {
     /**
@@ -23,25 +21,24 @@ namespace Org.BouncyCastle.Asn1.X9
             this.suppPubInfo = suppPubInfo;
         }
 
-		public OtherInfo(
-            Asn1Sequence seq)
+		public OtherInfo(Asn1Sequence seq)
         {
-            IEnumerator e = seq.GetEnumerator();
+            var e = seq.GetEnumerator();
 
 			e.MoveNext();
-            keyInfo = new KeySpecificInfo((Asn1Sequence) e.Current);
+            keyInfo = new KeySpecificInfo((Asn1Sequence)e.Current);
 
 			while (e.MoveNext())
             {
-                DerTaggedObject o = (DerTaggedObject) e.Current;
+                Asn1TaggedObject o = (Asn1TaggedObject)e.Current;
 
 				if (o.TagNo == 0)
                 {
-                    partyAInfo = (Asn1OctetString) o.GetObject();
+                    partyAInfo = (Asn1OctetString)o.GetObject();
                 }
                 else if ((int) o.TagNo == 2)
                 {
-                    suppPubInfo = (Asn1OctetString) o.GetObject();
+                    suppPubInfo = (Asn1OctetString)o.GetObject();
                 }
             }
         }
diff --git a/crypto/src/cms/CMSSignedDataGenerator.cs b/crypto/src/cms/CMSSignedDataGenerator.cs
index 20dc59f36..3db000896 100644
--- a/crypto/src/cms/CMSSignedDataGenerator.cs
+++ b/crypto/src/cms/CMSSignedDataGenerator.cs
@@ -136,12 +136,7 @@ namespace Org.BouncyCastle.Cms
                 }
 
                 IStreamCalculator calculator = sigCalc.CreateCalculator();
-
-#if PORTABLE
-				Stream sigStr = calculator.Stream;
-#else
 				Stream sigStr = new BufferedStream(calculator.Stream);
-#endif
 
 				Asn1Set signedAttr = null;
 				if (sAttr != null)
@@ -155,9 +150,7 @@ namespace Org.BouncyCastle.Cms
                     {
                         if (signed != null && signed[CmsAttributes.ContentType] != null)
                         {
-                            IDictionary tmpSigned = signed.ToDictionary();
-                            tmpSigned.Remove(CmsAttributes.ContentType);
-                            signed = new Asn1.Cms.AttributeTable(tmpSigned);
+							signed = signed.Remove(CmsAttributes.ContentType);
                         }
                     }
 
diff --git a/crypto/src/cms/CMSSignedDataStreamGenerator.cs b/crypto/src/cms/CMSSignedDataStreamGenerator.cs
index e247beea0..91a8b4a43 100644
--- a/crypto/src/cms/CMSSignedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSSignedDataStreamGenerator.cs
@@ -174,9 +174,7 @@ namespace Org.BouncyCastle.Cms
                         {
                             if (signed != null && signed[CmsAttributes.ContentType] != null)
                             {
-                                IDictionary tmpSigned = signed.ToDictionary();
-                                tmpSigned.Remove(CmsAttributes.ContentType);
-                                signed = new Asn1.Cms.AttributeTable(tmpSigned);
+								signed = signed.Remove(CmsAttributes.ContentType);
                             }
                         }
 
diff --git a/crypto/src/cms/DefaultAuthenticatedAttributeTableGenerator.cs b/crypto/src/cms/DefaultAuthenticatedAttributeTableGenerator.cs
index 2730d93e0..678d8269b 100644
--- a/crypto/src/cms/DefaultAuthenticatedAttributeTableGenerator.cs
+++ b/crypto/src/cms/DefaultAuthenticatedAttributeTableGenerator.cs
@@ -1,9 +1,9 @@
 using System;
 using System.Collections;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cms;
-using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Cms
 {
@@ -13,14 +13,14 @@ namespace Org.BouncyCastle.Cms
 	public class DefaultAuthenticatedAttributeTableGenerator
 		: CmsAttributeTableGenerator
 	{
-		private readonly IDictionary table;
+		private readonly IDictionary<DerObjectIdentifier, object> m_table;
 
 		/**
 		 * Initialise to use all defaults
 		 */
 		public DefaultAuthenticatedAttributeTableGenerator()
 		{
-			table =  Platform.CreateHashtable();
+			m_table = new Dictionary<DerObjectIdentifier, object>();
 		}
 
 		/**
@@ -33,11 +33,11 @@ namespace Org.BouncyCastle.Cms
 		{
 			if (attributeTable != null)
 			{
-				table = attributeTable.ToDictionary();
+				m_table = attributeTable.ToDictionary();
 			}
 			else
 			{
-				table = Platform.CreateHashtable();
+				m_table = new Dictionary<DerObjectIdentifier, object>();
 			}
 		}
 
@@ -51,12 +51,12 @@ namespace Org.BouncyCastle.Cms
 		 *
 		 * @return a filled in IDictionary of attributes.
 		 */
-		protected virtual IDictionary CreateStandardAttributeTable(
+		protected virtual IDictionary<DerObjectIdentifier, object> CreateStandardAttributeTable(
 			IDictionary parameters)
 		{
-            IDictionary std = Platform.CreateHashtable(table);
+            var std = new Dictionary<DerObjectIdentifier, object>(m_table);
 
-			if (!std.Contains(CmsAttributes.ContentType))
+			if (!std.ContainsKey(CmsAttributes.ContentType))
             {
                 DerObjectIdentifier contentType = (DerObjectIdentifier)
                     parameters[CmsAttributeTableParameter.ContentType];
@@ -65,7 +65,7 @@ namespace Org.BouncyCastle.Cms
                 std[attr.AttrType] = attr;
             }
 
-			if (!std.Contains(CmsAttributes.MessageDigest))
+			if (!std.ContainsKey(CmsAttributes.MessageDigest))
             {
                 byte[] messageDigest = (byte[])parameters[CmsAttributeTableParameter.Digest];
                 Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(CmsAttributes.MessageDigest,
@@ -76,14 +76,13 @@ namespace Org.BouncyCastle.Cms
             return std;
 		}
 
-        /**
+		/**
 		 * @param parameters source parameters
 		 * @return the populated attribute table
 		 */
-		public virtual AttributeTable GetAttributes(
-			IDictionary parameters)
+		public virtual AttributeTable GetAttributes(IDictionary parameters)
 		{
-            IDictionary table = CreateStandardAttributeTable(parameters);
+            var table = CreateStandardAttributeTable(parameters);
 			return new AttributeTable(table);
 		}
 	}
diff --git a/crypto/src/cms/DefaultSignedAttributeTableGenerator.cs b/crypto/src/cms/DefaultSignedAttributeTableGenerator.cs
index fad80b52b..8d0bca083 100644
--- a/crypto/src/cms/DefaultSignedAttributeTableGenerator.cs
+++ b/crypto/src/cms/DefaultSignedAttributeTableGenerator.cs
@@ -1,5 +1,6 @@
 using System;
 using System.Collections;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cms;
@@ -13,14 +14,14 @@ namespace Org.BouncyCastle.Cms
 	public class DefaultSignedAttributeTableGenerator
 		: CmsAttributeTableGenerator
 	{
-		private readonly IDictionary table;
+		private readonly IDictionary<DerObjectIdentifier, object> m_table;
 
 		/**
 		 * Initialise to use all defaults
 		 */
 		public DefaultSignedAttributeTableGenerator()
 		{
-			table = Platform.CreateHashtable();
+			m_table = new Dictionary<DerObjectIdentifier, object>();
 		}
 
 		/**
@@ -28,38 +29,18 @@ namespace Org.BouncyCastle.Cms
 		 *
 		 * @param attributeTable initial attribute table to use.
 		 */
-		public DefaultSignedAttributeTableGenerator(
-			AttributeTable attributeTable)
+		public DefaultSignedAttributeTableGenerator(AttributeTable attributeTable)
 		{
 			if (attributeTable != null)
 			{
-				table = attributeTable.ToDictionary();
+				m_table = attributeTable.ToDictionary();
 			}
 			else
 			{
-				table = Platform.CreateHashtable();
+				m_table = new Dictionary<DerObjectIdentifier, object>();
 			}
 		}
 
-#if PORTABLE
-		/**
-		 * Create a standard attribute table from the passed in parameters - this will
-		 * normally include contentType, signingTime, and messageDigest. If the constructor
-		 * using an AttributeTable was used, entries in it for contentType, signingTime, and
-		 * messageDigest will override the generated ones.
-		 *
-		 * @param parameters source parameters for table generation.
-		 *
-		 * @return a filled in Hashtable of attributes.
-		 */
-		protected virtual IDictionary createStandardAttributeTable(
-			IDictionary parameters)
-		{
-            IDictionary std = Platform.CreateHashtable(table);
-            DoCreateStandardAttributeTable(parameters, std);
-            return std;
-		}
-#else
         /**
 		 * Create a standard attribute table from the passed in parameters - this will
 		 * normally include contentType, signingTime, and messageDigest. If the constructor
@@ -70,21 +51,20 @@ namespace Org.BouncyCastle.Cms
 		 *
 		 * @return a filled in Hashtable of attributes.
 		 */
-		protected virtual Hashtable createStandardAttributeTable(
-			IDictionary parameters)
+		protected virtual IDictionary<DerObjectIdentifier, object> CreateStandardAttributeTable(IDictionary parameters)
 		{
-            Hashtable std = new Hashtable(table);
+            var std = new Dictionary<DerObjectIdentifier, object>(m_table);
             DoCreateStandardAttributeTable(parameters, std);
 			return std;
 		}
-#endif
 
-        private void DoCreateStandardAttributeTable(IDictionary parameters, IDictionary std)
+        private void DoCreateStandardAttributeTable(IDictionary parameters,
+			IDictionary<DerObjectIdentifier, object> std)
         {
             // contentType will be absent if we're trying to generate a counter signature.
             if (parameters.Contains(CmsAttributeTableParameter.ContentType))
             {
-                if (!std.Contains(CmsAttributes.ContentType))
+                if (!std.ContainsKey(CmsAttributes.ContentType))
                 {
                     DerObjectIdentifier contentType = (DerObjectIdentifier)
                         parameters[CmsAttributeTableParameter.ContentType];
@@ -94,14 +74,14 @@ namespace Org.BouncyCastle.Cms
                 }
             }
 
-            if (!std.Contains(CmsAttributes.SigningTime))
+            if (!std.ContainsKey(CmsAttributes.SigningTime))
             {
                 Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(CmsAttributes.SigningTime,
                     new DerSet(new Time(DateTime.UtcNow)));
                 std[attr.AttrType] = attr;
             }
 
-            if (!std.Contains(CmsAttributes.MessageDigest))
+            if (!std.ContainsKey(CmsAttributes.MessageDigest))
             {
                 byte[] messageDigest = (byte[])parameters[CmsAttributeTableParameter.Digest];
                 Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(CmsAttributes.MessageDigest,
@@ -117,7 +97,7 @@ namespace Org.BouncyCastle.Cms
 		public virtual AttributeTable GetAttributes(
 			IDictionary parameters)
 		{
-            IDictionary table = createStandardAttributeTable(parameters);
+            var table = CreateStandardAttributeTable(parameters);
 			return new AttributeTable(table);
 		}
 	}
diff --git a/crypto/src/pkix/Rfc3281CertPathUtilities.cs b/crypto/src/pkix/Rfc3281CertPathUtilities.cs
index a2673f2a1..686498b3e 100644
--- a/crypto/src/pkix/Rfc3281CertPathUtilities.cs
+++ b/crypto/src/pkix/Rfc3281CertPathUtilities.cs
@@ -277,7 +277,7 @@ namespace Org.BouncyCastle.Pkix
 			bool trusted = false;
 			foreach (TrustAnchor anchor in set)
 			{
-                IDictionary symbols = X509Name.RFC2253Symbols;
+                var symbols = X509Name.RFC2253Symbols;
                 if (acIssuerCert.SubjectDN.ToString(false, symbols).Equals(anchor.CAName)
 					|| acIssuerCert.Equals(anchor.TrustedCert))
 				{
diff --git a/crypto/src/tsp/TimeStampTokenGenerator.cs b/crypto/src/tsp/TimeStampTokenGenerator.cs
index afa1ef2e0..7d711eb22 100644
--- a/crypto/src/tsp/TimeStampTokenGenerator.cs
+++ b/crypto/src/tsp/TimeStampTokenGenerator.cs
@@ -1,7 +1,9 @@
 using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.IO;
 using System.Text;
+
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cmp;
 using Org.BouncyCastle.Asn1.Ess;
@@ -161,14 +163,14 @@ namespace Org.BouncyCastle.Tsp
             //
             // Add the ESSCertID attribute
             //
-            IDictionary signedAttrs;
+            IDictionary<DerObjectIdentifier, object> signedAttrs;
             if (signedAttr != null)
             {
                 signedAttrs = signedAttr.ToDictionary();
             }
             else
             {
-                signedAttrs = Platform.CreateHashtable();
+                signedAttrs = new Dictionary<DerObjectIdentifier, object>();
             }
 
             //try
diff --git a/crypto/src/util/collections/EnumerableProxy.cs b/crypto/src/util/collections/EnumerableProxy.cs
index 196b4d9df..36f78d342 100644
--- a/crypto/src/util/collections/EnumerableProxy.cs
+++ b/crypto/src/util/collections/EnumerableProxy.cs
@@ -37,12 +37,12 @@ namespace Org.BouncyCastle.Utilities.Collections
 			m_inner = inner;
 		}
 
-		IEnumerator IEnumerable.GetEnumerator()
+		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
 		{
 			return m_inner.GetEnumerator();
 		}
 
-		IEnumerator<T> IEnumerable<T>.GetEnumerator()
+		public IEnumerator<T> GetEnumerator()
 		{
 			return m_inner.GetEnumerator();
 		}
diff --git a/crypto/src/util/collections/ReadOnlyList.cs b/crypto/src/util/collections/ReadOnlyList.cs
index 70103022f..707c73bfd 100644
--- a/crypto/src/util/collections/ReadOnlyList.cs
+++ b/crypto/src/util/collections/ReadOnlyList.cs
@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
 
 namespace Org.BouncyCastle.Utilities.Collections
@@ -13,7 +12,7 @@ namespace Org.BouncyCastle.Utilities.Collections
             set { throw new NotSupportedException(); }
         }
 
-        IEnumerator IEnumerable.GetEnumerator()
+        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
         {
             return GetEnumerator();
         }
diff --git a/crypto/src/util/collections/UnmodifiableDictionary.cs b/crypto/src/util/collections/UnmodifiableDictionary.cs
index 0bdf70ad7..3b4ba22ae 100644
--- a/crypto/src/util/collections/UnmodifiableDictionary.cs
+++ b/crypto/src/util/collections/UnmodifiableDictionary.cs
@@ -26,7 +26,7 @@ namespace Org.BouncyCastle.Utilities.Collections
 
 		public abstract int Count { get; }
 
-		IEnumerator IEnumerable.GetEnumerator()
+		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
 		{
 			return GetEnumerator();
 		}
diff --git a/crypto/test/src/asn1/test/AttributeTableUnitTest.cs b/crypto/test/src/asn1/test/AttributeTableUnitTest.cs
index 4848c50fa..c6d69fa2b 100644
--- a/crypto/test/src/asn1/test/AttributeTableUnitTest.cs
+++ b/crypto/test/src/asn1/test/AttributeTableUnitTest.cs
@@ -74,7 +74,7 @@ namespace Org.BouncyCastle.Asn1.Tests
                 Fail("wrong vector size for single.");
             }
 
-            IDictionary t = table.ToDictionary();
+            var t = table.ToDictionary();
 
 			if (t.Count != 2)
             {
diff --git a/crypto/test/src/asn1/test/ParseTest.cs b/crypto/test/src/asn1/test/ParseTest.cs
index c649fdb8d..363e6d3d6 100644
--- a/crypto/test/src/asn1/test/ParseTest.cs
+++ b/crypto/test/src/asn1/test/ParseTest.cs
@@ -279,7 +279,7 @@ namespace Org.BouncyCastle.Asn1.Tests
 			Asn1StreamParser aIn = new Asn1StreamParser(longTagged);
 			Asn1TaggedObjectParser tagged = (Asn1TaggedObjectParser)aIn.ReadObject();
 
-			Assert.AreEqual(31, tagged.TagNo);
+            Assert.IsTrue(tagged.HasContextTag(31));
 		}
 
 		private void ParseEnveloped(
diff --git a/crypto/test/src/asn1/test/X509NameTest.cs b/crypto/test/src/asn1/test/X509NameTest.cs
index c6de1b1db..c344042a2 100644
--- a/crypto/test/src/asn1/test/X509NameTest.cs
+++ b/crypto/test/src/asn1/test/X509NameTest.cs
@@ -41,10 +41,10 @@ namespace Org.BouncyCastle.Asn1.Tests
             DerObjectIdentifier	oid,
             string				value)
         {
-            IDictionary attrs = new Hashtable();
+            var attrs = new Dictionary<DerObjectIdentifier, string>();
             attrs.Add(oid, value);
 
-            IList ord = new ArrayList();
+            var ord = new List<DerObjectIdentifier>();
             ord.Add(oid);
 
             X509Name name = new X509Name(ord, attrs);
@@ -60,10 +60,10 @@ namespace Org.BouncyCastle.Asn1.Tests
             DerObjectIdentifier	oid,
             string				val)
         {
-            IDictionary attrs = new Hashtable();
+            var attrs = new Dictionary<DerObjectIdentifier, string>();
             attrs.Add(oid, val);
 
-            IList ord = new ArrayList(attrs.Keys);
+            var ord = new List<DerObjectIdentifier>(attrs.Keys);
 
             X509Name name = new X509Name(new X509Name(ord, attrs).ToString());
 
@@ -127,14 +127,14 @@ namespace Org.BouncyCastle.Asn1.Tests
             //
             // composite
             //
-            IDictionary attrs = new Hashtable();
+            var attrs = new Dictionary<DerObjectIdentifier, string>();
             attrs.Add(X509Name.C, "AU");
             attrs.Add(X509Name.O, "The Legion of the Bouncy Castle");
             attrs.Add(X509Name.L, "Melbourne");
             attrs.Add(X509Name.ST, "Victoria");
             attrs.Add(X509Name.E, "feedback-crypto@bouncycastle.org");
 
-            IList order = new ArrayList();
+            var order = new List<DerObjectIdentifier>();
             order.Add(X509Name.C);
             order.Add(X509Name.O);
             order.Add(X509Name.L);
@@ -583,7 +583,7 @@ namespace Org.BouncyCastle.Asn1.Tests
                 Fail("Failed composite to string test got: " + n.ToString());
             }
 
-            IDictionary symbols = X509Name.DefaultSymbols;
+            var symbols = X509Name.DefaultSymbols;
             if (!n.ToString(true, symbols).Equals("L=Melbourne+OU=Ascot Vale,O=The Legion of the Bouncy Castle,C=AU"))
             {
                 Fail("Failed composite to string test got: " + n.ToString(true, symbols));
diff --git a/crypto/test/src/cmp/test/ProtectedMessageTest.cs b/crypto/test/src/cmp/test/ProtectedMessageTest.cs
index 1b7d84eea..98bae77ee 100644
--- a/crypto/test/src/cmp/test/ProtectedMessageTest.cs
+++ b/crypto/test/src/cmp/test/ProtectedMessageTest.cs
@@ -1,5 +1,6 @@
 using System;
 using System.Collections;
+using System.Collections.Generic;
 
 using NUnit.Framework;
 
@@ -321,8 +322,8 @@ namespace Org.BouncyCastle.Cmp.Tests
 
     public class TestCertBuilder
     {
-        IDictionary attrs = new Hashtable();
-        IList ord = new ArrayList();
+        IDictionary<DerObjectIdentifier, string> attrs = new Dictionary<DerObjectIdentifier, string>();
+        IList<DerObjectIdentifier> ord = new List<DerObjectIdentifier>();
         IList values = new ArrayList();
 
         private DateTime notBefore, notAfter;
@@ -366,7 +367,7 @@ namespace Org.BouncyCastle.Cmp.Tests
             set { this.subject = value; }
         }
 
-        public TestCertBuilder AddAttribute(DerObjectIdentifier name, object value)
+        public TestCertBuilder AddAttribute(DerObjectIdentifier name, string value)
         {
             attrs[name] = value;
             ord.Add(name);
diff --git a/crypto/test/src/cms/test/SignedDataStreamTest.cs b/crypto/test/src/cms/test/SignedDataStreamTest.cs
index 4ef6d9441..15924cc47 100644
--- a/crypto/test/src/cms/test/SignedDataStreamTest.cs
+++ b/crypto/test/src/cms/test/SignedDataStreamTest.cs
@@ -576,10 +576,9 @@ namespace Org.BouncyCastle.Cms.Tests
 		private class SignedGenAttributeTableGenerator
 			: DefaultSignedAttributeTableGenerator
 		{
-			public override AttributeTable GetAttributes(
-				IDictionary parameters)
+			public override AttributeTable GetAttributes(IDictionary parameters)
 			{
-				IDictionary table = createStandardAttributeTable(parameters);
+				var table = CreateStandardAttributeTable(parameters);
 
 				DerOctetString val = new DerOctetString((byte[])parameters[CmsAttributeTableParameter.Digest]);
 				Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(dummyOid1, new DerSet(val));
diff --git a/crypto/test/src/pkcs/test/PKCS10Test.cs b/crypto/test/src/pkcs/test/PKCS10Test.cs
index 9629bdd81..39b33e1b5 100644
--- a/crypto/test/src/pkcs/test/PKCS10Test.cs
+++ b/crypto/test/src/pkcs/test/PKCS10Test.cs
@@ -1,8 +1,5 @@
-#region Using directives
-
-using System;
 using System.Collections;
-using System.Text;
+using System.Collections.Generic;
 
 using NUnit.Framework;
 
@@ -12,12 +9,9 @@ using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Asn1.Pkcs;
 using Org.BouncyCastle.Crypto;
-using Org.BouncyCastle.Crypto.Generators;
 using Org.BouncyCastle.Utilities.Test;
 using Org.BouncyCastle.Security;
 
-#endregion
-
 namespace Org.BouncyCastle.Pkcs.Tests
 {
     [TestFixture]
@@ -42,14 +36,14 @@ namespace Org.BouncyCastle.Pkcs.Tests
 
             AsymmetricCipherKeyPair kp = kpg.GenerateKeyPair();
 
-            IDictionary attrs = new Hashtable();
+            var attrs = new Dictionary<DerObjectIdentifier, string>();
             attrs.Add(X509Name.C, "AU");
             attrs.Add(X509Name.O, "The Legion of the Bouncy Castle");
             attrs.Add(X509Name.L, "Melbourne");
             attrs.Add(X509Name.ST, "Victoria");
             attrs.Add(X509Name.EmailAddress, "feedback-crypto@bouncycastle.org");
 
-            IList order = new ArrayList();
+            var order = new List<DerObjectIdentifier>();
             order.Add(X509Name.C);
             order.Add(X509Name.O);
             order.Add(X509Name.L);
@@ -140,7 +134,7 @@ namespace Org.BouncyCastle.Pkcs.Tests
 
             AsymmetricCipherKeyPair pair = pGen.GenerateKeyPair();
 
-            IDictionary attrs = new Hashtable();
+            var attrs = new Dictionary<DerObjectIdentifier, string>();
 
             attrs.Add(X509Name.C, "AU");
             attrs.Add(X509Name.O, "The Legion of the Bouncy Castle");
@@ -148,7 +142,7 @@ namespace Org.BouncyCastle.Pkcs.Tests
             attrs.Add(X509Name.ST, "Victoria");
             attrs.Add(X509Name.EmailAddress, "feedback-crypto@bouncycastle.org");
 
-            X509Name subject = new X509Name(new ArrayList(attrs.Keys), attrs);
+            X509Name subject = new X509Name(new List<DerObjectIdentifier>(attrs.Keys), attrs);
 
             Pkcs10CertificationRequest req1 = new Pkcs10CertificationRequest(
 				"SHA1withRSA",
diff --git a/crypto/test/src/pkcs/test/PKCS12StoreTest.cs b/crypto/test/src/pkcs/test/PKCS12StoreTest.cs
index 91233db46..a500e5e63 100644
--- a/crypto/test/src/pkcs/test/PKCS12StoreTest.cs
+++ b/crypto/test/src/pkcs/test/PKCS12StoreTest.cs
@@ -1,5 +1,6 @@
 using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.IO;
 
 using NUnit.Framework;
@@ -861,21 +862,21 @@ namespace Org.BouncyCastle.Pkcs.Tests
 			//
 			// distinguished name table.
 			//
-            IDictionary issuerAttrs = new Hashtable();
+            var issuerAttrs = new Dictionary<DerObjectIdentifier, string>();
 			issuerAttrs.Add(X509Name.C, "AU");
 			issuerAttrs.Add(X509Name.O, "The Legion of the Bouncy Castle");
 			issuerAttrs.Add(X509Name.L, "Melbourne");
 			issuerAttrs.Add(X509Name.ST, "Victoria");
 			issuerAttrs.Add(X509Name.EmailAddress, issuerEmail);
 
-			IDictionary subjectAttrs = new Hashtable();
+			var subjectAttrs = new Dictionary<DerObjectIdentifier, string>();
 			subjectAttrs.Add(X509Name.C, "AU");
 			subjectAttrs.Add(X509Name.O, "The Legion of the Bouncy Castle");
 			subjectAttrs.Add(X509Name.L, "Melbourne");
 			subjectAttrs.Add(X509Name.ST, "Victoria");
 			subjectAttrs.Add(X509Name.EmailAddress, subjectEmail);
 
-			IList order = new ArrayList();
+			var order = new List<DerObjectIdentifier>();
 			order.Add(X509Name.C);
 			order.Add(X509Name.O);
 			order.Add(X509Name.L);
diff --git a/crypto/test/src/security/test/TestDotNetUtil.cs b/crypto/test/src/security/test/TestDotNetUtil.cs
index 899af016c..e2bb783ef 100644
--- a/crypto/test/src/security/test/TestDotNetUtil.cs
+++ b/crypto/test/src/security/test/TestDotNetUtil.cs
@@ -1,12 +1,12 @@
-#if !PORTABLE
-
 using System;
+using System.Collections;
+using System.Collections.Generic;
 using System.Security.Cryptography;
 using SystemX509 = System.Security.Cryptography.X509Certificates;
-using System.Collections;
 
 using NUnit.Framework;
 
+using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.Operators;
@@ -49,14 +49,14 @@ namespace Org.BouncyCastle.Security.Tests
 			DsaPrivateKeyParameters dsaPriv = new DsaPrivateKeyParameters(DsaPrivateX, para);
 			DsaPublicKeyParameters dsaPub = new DsaPublicKeyParameters(DSAPublicY, para);
 
-			IDictionary attrs = new Hashtable();
+			var attrs = new Dictionary<DerObjectIdentifier, string>();
 			attrs[X509Name.C] = "AU";
 			attrs[X509Name.O] = "The Legion of the Bouncy Castle";
 			attrs[X509Name.L] = "Melbourne";
 			attrs[X509Name.ST] = "Victoria";
 			attrs[X509Name.E] = "feedback-crypto@bouncycastle.org";
 
-			IList ord = new ArrayList(attrs.Keys);
+			var ord = new List<DerObjectIdentifier>(attrs.Keys);
 
 			X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
 
@@ -84,5 +84,3 @@ namespace Org.BouncyCastle.Security.Tests
 		}
 	}
 }
-
-#endif
diff --git a/crypto/test/src/test/CertTest.cs b/crypto/test/src/test/CertTest.cs
index 0e1cf1d70..964b1a6bd 100644
--- a/crypto/test/src/test/CertTest.cs
+++ b/crypto/test/src/test/CertTest.cs
@@ -1144,7 +1144,7 @@ namespace Org.BouncyCastle.Tests
             ord.Add(X509Name.ST);
             ord.Add(X509Name.E);
 
-            IList values = new ArrayList();
+            var values = new List<string>();
             values.Add("AU");
             values.Add("The Legion of the Bouncy Castle");
             values.Add("Melbourne");
@@ -1298,7 +1298,7 @@ namespace Org.BouncyCastle.Tests
             ord.Add(X509Name.ST);
             ord.Add(X509Name.E);
 
-            IList values = new ArrayList();
+            var values = new List<string>();
             values.Add("AU");
             values.Add("The Legion of the Bouncy Castle");
             values.Add("Melbourne");
@@ -1423,8 +1423,8 @@ namespace Org.BouncyCastle.Tests
             //
             // distinguished name table.
             //
-            IDictionary attrs = new Hashtable();
-            IList order = new ArrayList();
+            var attrs = new Dictionary<DerObjectIdentifier, string>();
+            var order = new List<DerObjectIdentifier>();
 
             attrs.Add(X509Name.C, "AU");
             attrs.Add(X509Name.O, "The Legion of the Bouncy Castle");
@@ -1552,8 +1552,8 @@ namespace Org.BouncyCastle.Tests
             //
             // distinguished name table.
             //
-            IDictionary attrs = new Hashtable();
-            IList order = new ArrayList();
+            var attrs = new Dictionary<DerObjectIdentifier, string>();
+            var order = new List<DerObjectIdentifier>();
 
             attrs.Add(X509Name.C, "AU");
             attrs.Add(X509Name.O, "The Legion of the Bouncy Castle");
@@ -2001,14 +2001,14 @@ namespace Org.BouncyCastle.Tests
             //
             // distinguished name table.
             //
-            IDictionary attrs = new Hashtable();
+            var attrs = new Dictionary<DerObjectIdentifier, string>();
             attrs.Add(X509Name.C, "AU");
             attrs.Add(X509Name.O, "The Legion of the Bouncy Castle");
             attrs.Add(X509Name.L, "Melbourne");
             attrs.Add(X509Name.ST, "Victoria");
             attrs.Add(X509Name.E, "feedback-crypto@bouncycastle.org");
 
-            IList order = new ArrayList();
+            var order = new List<DerObjectIdentifier>();
             order.Add(X509Name.C);
             order.Add(X509Name.O);
             order.Add(X509Name.L);
@@ -2095,7 +2095,7 @@ namespace Org.BouncyCastle.Tests
             ord.Add(X509Name.ST);
             ord.Add(X509Name.E);
 
-            IList values = new ArrayList();
+            var values = new List<string>();
             values.Add("AU");
             values.Add("The Legion of the Bouncy Castle");
             values.Add("Melbourne");
@@ -2355,7 +2355,7 @@ namespace Org.BouncyCastle.Tests
             ord.Add(X509Name.ST);
             ord.Add(X509Name.E);
 
-            IList values = new ArrayList();
+            var values = new List<string>();
             values.Add("AU");
             values.Add("The Legion of the Bouncy Castle");
             values.Add("Melbourne");
diff --git a/crypto/test/src/test/PKCS10CertRequestTest.cs b/crypto/test/src/test/PKCS10CertRequestTest.cs
index 94a53f9cf..fb913d7de 100644
--- a/crypto/test/src/test/PKCS10CertRequestTest.cs
+++ b/crypto/test/src/test/PKCS10CertRequestTest.cs
@@ -81,14 +81,14 @@ namespace Org.BouncyCastle.Tests
 
             AsymmetricCipherKeyPair kp = kpg.GenerateKeyPair();
 
-            IDictionary attrs = new Hashtable();
+            var attrs = new Dictionary<DerObjectIdentifier, string>();
             attrs.Add(X509Name.C, "AU");
             attrs.Add(X509Name.O, "The Legion of the Bouncy Castle");
             attrs.Add(X509Name.L, "Melbourne");
             attrs.Add(X509Name.ST, "Victoria");
             attrs.Add(X509Name.EmailAddress, "feedback-crypto@bouncycastle.org");
 
-            IList order = new ArrayList();
+            var order = new List<DerObjectIdentifier>();
             order.Add(X509Name.C);
             order.Add(X509Name.O);
             order.Add(X509Name.L);
diff --git a/crypto/test/src/test/PkixPolicyMappingTest.cs b/crypto/test/src/test/PkixPolicyMappingTest.cs
index 097826907..5ca33bf6a 100644
--- a/crypto/test/src/test/PkixPolicyMappingTest.cs
+++ b/crypto/test/src/test/PkixPolicyMappingTest.cs
@@ -54,7 +54,7 @@ namespace Org.BouncyCastle.Tests
 			AsymmetricKeyParameter caPrivKey,
 			AsymmetricKeyParameter caPubKey,
 			Asn1EncodableVector policies,
-			Hashtable policyMap)
+			IDictionary<string, string> policyMap)
 		{
 			string issuer = "C=JP, O=policyMappingAdditionalTest, OU=trustAnchor";
 			string subject = "C=JP, O=policyMappingAdditionalTest, OU=intmedCA";
@@ -232,7 +232,7 @@ namespace Org.BouncyCastle.Tests
 
 			X509Certificate trustCert = CreateTrustCert(caPubKey, caPrivKeySpec);
 			Asn1EncodableVector intPolicies = null;
-			Hashtable map = null;
+			IDictionary<string, string> map = null;
 			Asn1EncodableVector policies = null;
 			ISet<string> requirePolicies = null;
 			X509Certificate intCert = null;
@@ -241,7 +241,7 @@ namespace Org.BouncyCastle.Tests
 			// valid test_00
 			intPolicies = new Asn1EncodableVector();
 			intPolicies.Add(new PolicyInformation(new DerObjectIdentifier("2.5.29.32.0")));
-			map = new Hashtable();
+			map = new Dictionary<string, string>();
 			map["2.16.840.1.101.3.2.1.48.1"] = "2.16.840.1.101.3.2.1.48.2";
 			intCert = CreateIntmedCert(intPubKey, caPrivKey, caPubKey, intPolicies, map);
 
@@ -256,7 +256,7 @@ namespace Org.BouncyCastle.Tests
 			// test_01
 			intPolicies = new Asn1EncodableVector();
 			intPolicies.Add(new PolicyInformation(new DerObjectIdentifier("2.5.29.32.0")));
-			map = new Hashtable();
+			map = new Dictionary<string, string>();
 			map["2.16.840.1.101.3.2.1.48.1"] = "2.16.840.1.101.3.2.1.48.2";
 			intCert = CreateIntmedCert(intPubKey, caPrivKey, caPubKey, intPolicies, map);
 
@@ -272,7 +272,7 @@ namespace Org.BouncyCastle.Tests
 			// test_02
 			intPolicies = new Asn1EncodableVector();
 			intPolicies.Add(new PolicyInformation(new DerObjectIdentifier("2.5.29.32.0")));
-			map = new Hashtable();
+			map = new Dictionary<string, string>();
 			map["2.16.840.1.101.3.2.1.48.1"] = "2.16.840.1.101.3.2.1.48.2";
 			intCert = CreateIntmedCert(intPubKey, caPrivKey, caPubKey, intPolicies, map);
 
@@ -289,7 +289,7 @@ namespace Org.BouncyCastle.Tests
 			intPolicies = new Asn1EncodableVector();
 			intPolicies.Add(new PolicyInformation(new DerObjectIdentifier("2.16.840.1.101.3.2.1.48.3")));
 			intPolicies.Add(new PolicyInformation(new DerObjectIdentifier("2.5.29.32.0")));
-			map = new Hashtable();
+			map = new Dictionary<string, string>();
 			map["2.16.840.1.101.3.2.1.48.1"] = "2.16.840.1.101.3.2.1.48.2";
 			intCert = CreateIntmedCert(intPubKey, caPrivKey, caPubKey, intPolicies, map);
 
@@ -306,7 +306,7 @@ namespace Org.BouncyCastle.Tests
 			intPolicies = new Asn1EncodableVector();
 			intPolicies.Add(new PolicyInformation(new DerObjectIdentifier("2.16.840.1.101.3.2.1.48.3")));
 			intPolicies.Add(new PolicyInformation(new DerObjectIdentifier("2.5.29.32.0")));
-			map = new Hashtable();
+			map = new Dictionary<string, string>();
 			map["2.16.840.1.101.3.2.1.48.1"] = "2.16.840.1.101.3.2.1.48.2";
 			intCert = CreateIntmedCert(intPubKey, caPrivKey, caPubKey, intPolicies, map);
 
@@ -322,7 +322,7 @@ namespace Org.BouncyCastle.Tests
 			// test_05
 			intPolicies = new Asn1EncodableVector();
 			intPolicies.Add(new PolicyInformation(new DerObjectIdentifier("2.5.29.32.0")));
-			map = new Hashtable();
+			map = new Dictionary<string, string>();
 			map["2.16.840.1.101.3.2.1.48.1"] = "2.16.840.1.101.3.2.1.48.2";
 			intCert = CreateIntmedCert(intPubKey, caPrivKey, caPubKey, intPolicies, map);
 
@@ -338,7 +338,7 @@ namespace Org.BouncyCastle.Tests
 			// test_06
 			intPolicies = new Asn1EncodableVector();
 			intPolicies.Add(new PolicyInformation(new DerObjectIdentifier("2.5.29.32.0")));
-			map = new Hashtable();
+			map = new Dictionary<string, string>();
 			map["2.16.840.1.101.3.2.1.48.1"] = "2.16.840.1.101.3.2.1.48.2";
 			intCert = CreateIntmedCert(intPubKey, caPrivKey, caPubKey, intPolicies, map);
 
@@ -354,7 +354,7 @@ namespace Org.BouncyCastle.Tests
 			// test_07
 			intPolicies = new Asn1EncodableVector();
 			intPolicies.Add(new PolicyInformation(new DerObjectIdentifier("2.5.29.32.0")));
-			map = new Hashtable();
+			map = new Dictionary<string, string>();
 			map["2.16.840.1.101.3.2.1.48.1"] = "2.16.840.1.101.3.2.1.48.2";
 			intCert = CreateIntmedCert(intPubKey, caPrivKey, caPubKey, intPolicies, map);
 
@@ -370,7 +370,7 @@ namespace Org.BouncyCastle.Tests
 			// test_08
 			intPolicies = new Asn1EncodableVector();
 			intPolicies.Add(new PolicyInformation(new DerObjectIdentifier("2.5.29.32.0")));
-			map = new Hashtable();
+			map = new Dictionary<string, string>();
 			map["2.16.840.1.101.3.2.1.48.1"] = "2.16.840.1.101.3.2.1.48.2";
 			intCert = CreateIntmedCert(intPubKey, caPrivKey, caPubKey, intPolicies, map);
 
diff --git a/crypto/test/src/tsp/test/NewTspTest.cs b/crypto/test/src/tsp/test/NewTspTest.cs
index 3bcc73aa5..34be0dadf 100644
--- a/crypto/test/src/tsp/test/NewTspTest.cs
+++ b/crypto/test/src/tsp/test/NewTspTest.cs
@@ -869,14 +869,14 @@ namespace Org.BouncyCastle.Tsp.Tests
 			//
 			// Add the ESSCertID attribute
 			//
-			IDictionary signedAttrs;
+			IDictionary<DerObjectIdentifier, object> signedAttrs;
 			if (signedAttr != null)
 			{
 				signedAttrs = signedAttr.ToDictionary();
 			}
 			else
 			{
-				signedAttrs = new Hashtable();
+				signedAttrs = new Dictionary<DerObjectIdentifier, object>();
 			}
 
             string digestName = TspTestUtil.GetDigestAlgName(digestOID);
diff --git a/crypto/test/src/tsp/test/TSPTest.cs b/crypto/test/src/tsp/test/TSPTest.cs
index 3f2eed10b..06c20e4bd 100644
--- a/crypto/test/src/tsp/test/TSPTest.cs
+++ b/crypto/test/src/tsp/test/TSPTest.cs
@@ -649,21 +649,21 @@ namespace Org.BouncyCastle.Tsp.Tests
 		}
 
         internal static SignerInfoGenerator MakeInfoGenerator(AsymmetricKeyParameter key, X509Certificate cert,
-			string digestOID, Asn1.Cms.AttributeTable signedAttr, Asn1.Cms.AttributeTable unsignedAttr)
+			string digestOID, AttributeTable signedAttr, AttributeTable unsignedAttr)
         {
             TspUtil.ValidateCertificate(cert);
 
 			//
 			// Add the ESSCertID attribute
 			//
-			IDictionary signedAttrs;
+			IDictionary<DerObjectIdentifier, object> signedAttrs;
 			if (signedAttr != null)
 			{
 				signedAttrs = signedAttr.ToDictionary();
 			}
 			else
 			{
-				signedAttrs = new Hashtable();
+				signedAttrs = new Dictionary<DerObjectIdentifier, object>();
 			}
 
 			string digestName = TspTestUtil.GetDigestAlgName(digestOID);
@@ -672,11 +672,10 @@ namespace Org.BouncyCastle.Tsp.Tests
 
 			Asn1SignatureFactory sigfact = new Asn1SignatureFactory(signatureName, key);
 			return new SignerInfoGeneratorBuilder()
-			 .WithSignedAttributeGenerator(
-				new DefaultSignedAttributeTableGenerator(
-					new Asn1.Cms.AttributeTable(signedAttrs)))
-			  .WithUnsignedAttributeGenerator(
-				new SimpleAttributeTableGenerator(unsignedAttr))
+				.WithSignedAttributeGenerator(
+					new DefaultSignedAttributeTableGenerator(new AttributeTable(signedAttrs)))
+				.WithUnsignedAttributeGenerator(
+					new SimpleAttributeTableGenerator(unsignedAttr))
 				.Build(sigfact, cert);
 		}
 	}
diff --git a/crypto/test/src/x509/test/TestCertificateGen.cs b/crypto/test/src/x509/test/TestCertificateGen.cs
index a4c548021..d1ac173bc 100644
--- a/crypto/test/src/x509/test/TestCertificateGen.cs
+++ b/crypto/test/src/x509/test/TestCertificateGen.cs
@@ -1,8 +1,10 @@
 using System;
 using System.Collections;
+using System.Collections.Generic;
 
 using NUnit.Framework;
 
+using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Asn1.X9;
 using Org.BouncyCastle.Crypto.Digests;
@@ -73,21 +75,21 @@ namespace Org.BouncyCastle.X509.Tests
             RsaKeyParameters rsaPublic = new RsaKeyParameters(false, rsaPubMod, rsaPubExp);
 			RsaPrivateCrtKeyParameters rsaPrivate = new RsaPrivateCrtKeyParameters(rsaPrivMod, rsaPubExp, rsaPrivExp, rsaPrivP, rsaPrivQ, rsaPrivDP, rsaPrivDQ, rsaPrivQinv);
 
-			IDictionary attrs = new Hashtable();
+			var attrs = new Dictionary<DerObjectIdentifier, string>();
             attrs[X509Name.C] = "AU";
             attrs[X509Name.O] = "The Legion of the Bouncy Castle";
             attrs[X509Name.L] = "Melbourne";
             attrs[X509Name.ST] = "Victoria";
             attrs[X509Name.E] = "feedback-crypto@bouncycastle.org";
 
-            IList ord = new ArrayList();
+            var ord = new List<DerObjectIdentifier>();
             ord.Add(X509Name.C);
             ord.Add(X509Name.O);
             ord.Add(X509Name.L);
             ord.Add(X509Name.ST);
             ord.Add(X509Name.E);
 
-			IList values = new ArrayList();
+			var values = new List<string>();
 			values.Add("AU");
             values.Add("The Legion of the Bouncy Castle");
             values.Add("Melbourne");
@@ -149,21 +151,21 @@ namespace Org.BouncyCastle.X509.Tests
             DsaPrivateKeyParameters dsaPriv = new DsaPrivateKeyParameters(DsaPrivateX, para);
             DsaPublicKeyParameters dsaPub = new DsaPublicKeyParameters(DSAPublicY, para);
 
-            IDictionary attrs = new Hashtable();
+            var attrs = new Dictionary<DerObjectIdentifier, string>();
             attrs[X509Name.C] = "AU";
             attrs[X509Name.O] = "The Legion of the Bouncy Castle";
             attrs[X509Name.L] = "Melbourne";
             attrs[X509Name.ST] = "Victoria";
             attrs[X509Name.E] = "feedback-crypto@bouncycastle.org";
 
-            IList ord = new ArrayList();
+            var ord = new List<DerObjectIdentifier>();
             ord.Add(X509Name.C);
             ord.Add(X509Name.O);
             ord.Add(X509Name.L);
             ord.Add(X509Name.ST);
             ord.Add(X509Name.E);
 
-            IList values = new ArrayList();
+            var values = new List<string>();
 			values.Add("AU");
             values.Add("The Legion of the Bouncy Castle");
             values.Add("Melbourne");
@@ -229,21 +231,21 @@ namespace Org.BouncyCastle.X509.Tests
                 curve.ValidatePoint(ECPubQX, ECPubQY), ecDomain);
             ECPrivateKeyParameters ecPriv = new ECPrivateKeyParameters("ECDSA", ECPrivD, ecDomain);
 
-            IDictionary attrs = new Hashtable();
+            var attrs = new Dictionary<DerObjectIdentifier, string>();
 			attrs[X509Name.C] = "AU";
             attrs[X509Name.O] = "The Legion of the Bouncy Castle";
             attrs[X509Name.L] = "Melbourne";
             attrs[X509Name.ST] = "Victoria";
             attrs[X509Name.E] = "feedback-crypto@bouncycastle.org";
 
-            IList ord = new ArrayList();
+            var ord = new List<DerObjectIdentifier>();
             ord.Add(X509Name.C);
             ord.Add(X509Name.O);
             ord.Add(X509Name.L);
             ord.Add(X509Name.ST);
             ord.Add(X509Name.E);
 
-			IList values = new ArrayList();
+			var values = new List<string>();
 			values.Add("AU");
             values.Add("The Legion of the Bouncy Castle");
             values.Add("Melbourne");