/// <summary>Creates a new instance of the specified cryptographic object with the specified arguments.</summary> /// <returns>A new instance of the specified cryptographic object.</returns> /// <param name="name">The simple name of the cryptographic object of which to create an instance. </param> /// <param name="args">The arguments used to create the specified cryptographic object. </param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="name" /> parameter is null. </exception> /// <exception cref="T:System.Reflection.TargetInvocationException">The algorithm described by the <paramref name="name" /> parameter was used with Federal Information Processing Standards (FIPS) mode enabled, but is not FIPS compatible.</exception> public static object CreateFromName(string name, params object[] args) { if (name == null) { throw new ArgumentNullException("name"); } object obj = CryptoConfig.lockObject; lock (obj) { if (CryptoConfig.algorithms == null) { CryptoConfig.Initialize(); } } object result; try { string text = (string)CryptoConfig.algorithms[name]; if (text == null) { text = name; } Type type = Type.GetType(text); result = Activator.CreateInstance(type, args); } catch { result = null; } return(result); }
/// <summary>Gets the object identifier (OID) of the algorithm corresponding to the specified simple name.</summary> /// <returns>The OID of the specified algorithm.</returns> /// <param name="name">The simple name of the algorithm for which to get the OID. </param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="name" /> parameter is null. </exception> public static string MapNameToOID(string name) { if (name == null) { throw new ArgumentNullException("name"); } object obj = CryptoConfig.lockObject; lock (obj) { if (CryptoConfig.oid == null) { CryptoConfig.Initialize(); } } return((string)CryptoConfig.oid[name]); }