/// <summary>Encodes the specified object identifier (OID).</summary> /// <returns>A byte array containing the encoded OID.</returns> /// <param name="str">The OID to encode. </param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="str" /> parameter is null. </exception> /// <exception cref="T:System.Security.Cryptography.CryptographicUnexpectedOperationException">An error occurred while encoding the OID. </exception> public static byte[] EncodeOID(string str) { if (str == null) { throw new ArgumentNullException("str"); } char[] separator = new char[] { '.' }; string[] array = str.Split(separator); if (array.Length < 2) { throw new CryptographicUnexpectedOperationException(Locale.GetText("OID must have at least two parts")); } byte[] array2 = new byte[str.Length]; try { byte b = Convert.ToByte(array[0]); byte b2 = Convert.ToByte(array[1]); array2[2] = Convert.ToByte((int)(b * 40 + b2)); } catch { throw new CryptographicUnexpectedOperationException(Locale.GetText("Invalid OID")); } int num = 3; for (int i = 2; i < array.Length; i++) { long num2 = Convert.ToInt64(array[i]); if (num2 > 127L) { byte[] array3 = CryptoConfig.EncodeLongNumber(num2); Buffer.BlockCopy(array3, 0, array2, num, array3.Length); num += array3.Length; } else { array2[num++] = Convert.ToByte(num2); } } int num3 = 2; byte[] array4 = new byte[num]; array4[0] = 6; if (num > 127) { throw new CryptographicUnexpectedOperationException(Locale.GetText("OID > 127 bytes")); } array4[1] = Convert.ToByte(num - 2); Buffer.BlockCopy(array2, num3, array4, num3, num - num3); return(array4); }