Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Oid Class
Collapse the table of content
Expand the table of content

Oid Class

Represents a cryptographic object identifier. This class cannot be inherited.


Namespace:  System.Security.Cryptography
Assembly:  System (in System.dll)

Public NotInheritable Class Oid

The Oid type exposes the following members.

Public methodOidInitializes a new instance of the Oid class.
Public methodOid(Oid)Initializes a new instance of the Oid class using the specified Oid object.
Public methodOid(String)Initializes a new instance of the Oid class using a string value of an Oid object.
Public methodOid(String, String)Initializes a new instance of the Oid class using the specified value and friendly name.

Public propertyFriendlyNameGets or sets the friendly name of the identifier.
Public propertyValueGets or sets the dotted number of the identifier.

Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodStatic memberFromFriendlyNameCreates an Oid object from an OID friendly name by searching the specified group.
Public methodStatic memberFromOidValueCreates an Oid object by using the specified OID value and group.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Cryptographic object identifiers consist of a value/name pair. If one property in a pair is set to a known value, the other property is updated automatically to a corresponding value. For example, if the Value property is set to "", the FriendlyName property, which is localized, is set automatically to "Secure Email".

The following code example shows how to use the Oid class.

Imports System
Imports System.Security.Cryptography

Public Class OidSample
   Shared msg As String 
   Public Shared Sub Main()
      ' Assign values to strings. 
      Dim Value1 As String = "1.2.840.113549.1.1.1" 
      Dim Name1 As String = "3DES" 
      Dim Value2 As String = "" 
      Dim InvalidName As String = "This name is not a valid name" 
      Dim InvalidValue As String = "" 

      ' Create new Oid objects using the specified values. 
      ' Note that the corresponding Value or Friendly Name property is automatically added to the object. 
      Dim o1 As New Oid(Value1)
      Dim o2 As New Oid(Name1)

      ' Create a new Oid object using the specified Value and Friendly Name properties. 
      ' Note that the two are not compared to determine if the Value is associated  
      '  with the Friendly Name. 
      Dim o3 As New Oid(Value2, InvalidName)

      'Create a new Oid object using the specified Value. Note that if the value 
      '  is invalid or not known, no value is assigned to the Friendly Name property. 
      Dim o4 As New Oid(InvalidValue)

      'Write out the property information of the Oid objects.
	msg = "Oid1: Automatically assigned Friendly Name: " & o1.FriendlyName & ", " & o1.Value
      'Console.WriteLine("Oid1: Automatically assigned Friendly Name: {0}, {1}", o1.FriendlyName, o1.Value) 

      'Console.WriteLine("Oid2: Automatically assigned Value: {0}, {1}", o2.FriendlyName, o2.Value)
	msg = "Oid2: Automatically assigned Value: " & o2.FriendlyName & ", " & o2.Value

      'Console.WriteLine("Oid3: Name and Value not compared: {0}, {1}", o3.FriendlyName, o3.Value)
	msg = "Oid3: Name and Value not compared: " & o3.FriendlyName & ", " & o3.Value

     ' Console.WriteLine("Oid4: Invalid Value used: {0}, {1} {2}", o4.FriendlyName, o4.Value, Environment.NewLine)
	msg = "Oid4: Invalid Value used: " & o4.FriendlyName & ", " & o4.Value

      'Create an Oid collection and add several Oid objects. 
      Dim oc As New OidCollection()
     ' Console.WriteLine("Number of Oids in the collection: {0}", oc.Count) 
      ' Console.WriteLine("Is synchronized: {0} {1}", oc.IsSynchronized, Environment.NewLine)

	msg = "Number of Oids in the collection: " & oc.Count
	msg = "Is synchronized: " & oc.IsSynchronized

      'Create an enumerator for moving through the collection. 
      Dim oe As OidEnumerator = oc.GetEnumerator()
      'You must execute a MoveNext() to get to the first item in the collection.
      ' Write out Oids in the collection. 
      'Console.WriteLine("First Oid in collection: {0},{1}", oe.Current.FriendlyName, oe.Current.Value)
	msg = "First Oid in collection: " & oe.Current.FriendlyName & ", " & oe.Current.Value

     ' Console.WriteLine("Second Oid in collection: {0},{1}", oe.Current.FriendlyName, oe.Current.Value)
	msg = "Second Oid in collection: " & oe.Current.FriendlyName & ", " & oe.Current.Value

      'Return index in the collection to the beginning.
   End Sub 'Main
End Class 'OidSample

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2015 Microsoft