Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CryptoConfig.cs
Go to the documentation of this file.
7
9
10public class CryptoConfig
11{
13
15
17
19
20 public static bool AllowOnlyFipsAlgorithms => false;
21
23 {
24 get
25 {
26 if (s_defaultOidHT != null)
27 {
28 return s_defaultOidHT;
29 }
30 int capacity = 37;
32 dictionary.Add("SHA", "1.3.14.3.2.26");
33 dictionary.Add("SHA1", "1.3.14.3.2.26");
34 dictionary.Add("System.Security.Cryptography.SHA1", "1.3.14.3.2.26");
35 dictionary.Add("System.Security.Cryptography.SHA1CryptoServiceProvider", "1.3.14.3.2.26");
36 dictionary.Add("System.Security.Cryptography.SHA1Cng", "1.3.14.3.2.26");
37 dictionary.Add("System.Security.Cryptography.SHA1Managed", "1.3.14.3.2.26");
38 dictionary.Add("SHA256", "2.16.840.1.101.3.4.2.1");
39 dictionary.Add("System.Security.Cryptography.SHA256", "2.16.840.1.101.3.4.2.1");
40 dictionary.Add("System.Security.Cryptography.SHA256CryptoServiceProvider", "2.16.840.1.101.3.4.2.1");
41 dictionary.Add("System.Security.Cryptography.SHA256Cng", "2.16.840.1.101.3.4.2.1");
42 dictionary.Add("System.Security.Cryptography.SHA256Managed", "2.16.840.1.101.3.4.2.1");
43 dictionary.Add("SHA384", "2.16.840.1.101.3.4.2.2");
44 dictionary.Add("System.Security.Cryptography.SHA384", "2.16.840.1.101.3.4.2.2");
45 dictionary.Add("System.Security.Cryptography.SHA384CryptoServiceProvider", "2.16.840.1.101.3.4.2.2");
46 dictionary.Add("System.Security.Cryptography.SHA384Cng", "2.16.840.1.101.3.4.2.2");
47 dictionary.Add("System.Security.Cryptography.SHA384Managed", "2.16.840.1.101.3.4.2.2");
48 dictionary.Add("SHA512", "2.16.840.1.101.3.4.2.3");
49 dictionary.Add("System.Security.Cryptography.SHA512", "2.16.840.1.101.3.4.2.3");
50 dictionary.Add("System.Security.Cryptography.SHA512CryptoServiceProvider", "2.16.840.1.101.3.4.2.3");
51 dictionary.Add("System.Security.Cryptography.SHA512Cng", "2.16.840.1.101.3.4.2.3");
52 dictionary.Add("System.Security.Cryptography.SHA512Managed", "2.16.840.1.101.3.4.2.3");
53 dictionary.Add("RIPEMD160", "1.3.36.3.2.1");
54 dictionary.Add("System.Security.Cryptography.RIPEMD160", "1.3.36.3.2.1");
55 dictionary.Add("System.Security.Cryptography.RIPEMD160Managed", "1.3.36.3.2.1");
56 dictionary.Add("MD5", "1.2.840.113549.2.5");
57 dictionary.Add("System.Security.Cryptography.MD5", "1.2.840.113549.2.5");
58 dictionary.Add("System.Security.Cryptography.MD5CryptoServiceProvider", "1.2.840.113549.2.5");
59 dictionary.Add("System.Security.Cryptography.MD5Managed", "1.2.840.113549.2.5");
60 dictionary.Add("TripleDESKeyWrap", "1.2.840.113549.1.9.16.3.6");
61 dictionary.Add("RC2", "1.2.840.113549.3.2");
62 dictionary.Add("System.Security.Cryptography.RC2CryptoServiceProvider", "1.2.840.113549.3.2");
63 dictionary.Add("DES", "1.3.14.3.2.7");
64 dictionary.Add("System.Security.Cryptography.DESCryptoServiceProvider", "1.3.14.3.2.7");
65 dictionary.Add("TripleDES", "1.2.840.113549.3.7");
66 dictionary.Add("System.Security.Cryptography.TripleDESCryptoServiceProvider", "1.2.840.113549.3.7");
68 return s_defaultOidHT;
69 }
70 }
71
73 {
74 get
75 {
76 if (s_defaultNameHT != null)
77 {
78 return s_defaultNameHT;
79 }
91 string value = "System.Security.Cryptography.SHA1CryptoServiceProvider, System.Security.Cryptography.Csp";
92 string value2 = "System.Security.Cryptography.MD5CryptoServiceProvider,System.Security.Cryptography.Csp";
93 string value3 = "System.Security.Cryptography.RSACryptoServiceProvider, System.Security.Cryptography.Csp";
94 string value4 = "System.Security.Cryptography.DSACryptoServiceProvider, System.Security.Cryptography.Csp";
95 string value5 = "System.Security.Cryptography.DESCryptoServiceProvider, System.Security.Cryptography.Csp";
96 string value6 = "System.Security.Cryptography.TripleDESCryptoServiceProvider, System.Security.Cryptography.Csp";
97 string value7 = "System.Security.Cryptography.RC2CryptoServiceProvider, System.Security.Cryptography.Csp";
98 string value8 = "System.Security.Cryptography.RNGCryptoServiceProvider, System.Security.Cryptography.Csp";
99 string value9 = "System.Security.Cryptography.AesCryptoServiceProvider, System.Security.Cryptography.Csp";
100 string value10 = "System.Security.Cryptography.ECDsaCng, System.Security.Cryptography.Cng";
101 dictionary.Add("RandomNumberGenerator", value8);
102 dictionary.Add("System.Security.Cryptography.RandomNumberGenerator", value8);
103 dictionary.Add("SHA", value);
104 dictionary.Add("SHA1", value);
105 dictionary.Add("System.Security.Cryptography.SHA1", value);
106 dictionary.Add("System.Security.Cryptography.HashAlgorithm", value);
107 dictionary.Add("MD5", value2);
108 dictionary.Add("System.Security.Cryptography.MD5", value2);
109 dictionary.Add("SHA256", typeFromHandle8);
110 dictionary.Add("SHA-256", typeFromHandle8);
111 dictionary.Add("System.Security.Cryptography.SHA256", typeFromHandle8);
112 dictionary.Add("SHA384", typeFromHandle9);
113 dictionary.Add("SHA-384", typeFromHandle9);
114 dictionary.Add("System.Security.Cryptography.SHA384", typeFromHandle9);
116 dictionary.Add("SHA-512", typeFromHandle10);
117 dictionary.Add("System.Security.Cryptography.SHA512", typeFromHandle10);
118 dictionary.Add("System.Security.Cryptography.HMAC", typeFromHandle2);
119 dictionary.Add("System.Security.Cryptography.KeyedHashAlgorithm", typeFromHandle2);
120 dictionary.Add("HMACMD5", typeFromHandle);
121 dictionary.Add("System.Security.Cryptography.HMACMD5", typeFromHandle);
122 dictionary.Add("HMACSHA1", typeFromHandle2);
123 dictionary.Add("System.Security.Cryptography.HMACSHA1", typeFromHandle2);
124 dictionary.Add("HMACSHA256", typeFromHandle3);
125 dictionary.Add("System.Security.Cryptography.HMACSHA256", typeFromHandle3);
126 dictionary.Add("HMACSHA384", typeFromHandle4);
127 dictionary.Add("System.Security.Cryptography.HMACSHA384", typeFromHandle4);
128 dictionary.Add("HMACSHA512", typeFromHandle5);
129 dictionary.Add("System.Security.Cryptography.HMACSHA512", typeFromHandle5);
130 dictionary.Add("RSA", value3);
131 dictionary.Add("System.Security.Cryptography.RSA", value3);
132 dictionary.Add("System.Security.Cryptography.AsymmetricAlgorithm", value3);
134 {
135 dictionary.Add("DSA", value4);
136 dictionary.Add("System.Security.Cryptography.DSA", value4);
137 }
139 {
140 dictionary.Add("ECDsa", value10);
141 }
142 dictionary.Add("ECDsaCng", value10);
143 dictionary.Add("System.Security.Cryptography.ECDsaCng", value10);
144 dictionary.Add("DES", value5);
145 dictionary.Add("System.Security.Cryptography.DES", value5);
146 dictionary.Add("3DES", value6);
147 dictionary.Add("TripleDES", value6);
148 dictionary.Add("Triple DES", value6);
149 dictionary.Add("System.Security.Cryptography.TripleDES", value6);
150 dictionary.Add("RC2", value7);
151 dictionary.Add("System.Security.Cryptography.RC2", value7);
152 dictionary.Add("Rijndael", typeFromHandle6);
153 dictionary.Add("System.Security.Cryptography.Rijndael", typeFromHandle6);
154 dictionary.Add("System.Security.Cryptography.SymmetricAlgorithm", typeFromHandle6);
155 dictionary.Add("AES", value9);
156 dictionary.Add("AesCryptoServiceProvider", value9);
157 dictionary.Add("System.Security.Cryptography.AesCryptoServiceProvider", value9);
158 dictionary.Add("AesManaged", typeFromHandle7);
159 dictionary.Add("System.Security.Cryptography.AesManaged", typeFromHandle7);
160 dictionary.Add("http://www.w3.org/2000/09/xmldsig#sha1", value);
161 dictionary.Add("http://www.w3.org/2001/04/xmlenc#sha256", typeFromHandle8);
162 dictionary.Add("http://www.w3.org/2001/04/xmlenc#sha512", typeFromHandle10);
163 dictionary.Add("http://www.w3.org/2001/04/xmlenc#des-cbc", value5);
164 dictionary.Add("http://www.w3.org/2001/04/xmlenc#tripledes-cbc", value6);
165 dictionary.Add("http://www.w3.org/2001/04/xmlenc#kw-tripledes", value6);
166 dictionary.Add("http://www.w3.org/2001/04/xmlenc#aes128-cbc", typeFromHandle6);
167 dictionary.Add("http://www.w3.org/2001/04/xmlenc#kw-aes128", typeFromHandle6);
168 dictionary.Add("http://www.w3.org/2001/04/xmlenc#aes192-cbc", typeFromHandle6);
169 dictionary.Add("http://www.w3.org/2001/04/xmlenc#kw-aes192", typeFromHandle6);
170 dictionary.Add("http://www.w3.org/2001/04/xmlenc#aes256-cbc", typeFromHandle6);
171 dictionary.Add("http://www.w3.org/2001/04/xmlenc#kw-aes256", typeFromHandle6);
172 dictionary.Add("http://www.w3.org/2000/09/xmldsig#hmac-sha1", typeFromHandle2);
173 dictionary.Add("http://www.w3.org/2001/04/xmldsig-more#md5", value2);
174 dictionary.Add("http://www.w3.org/2001/04/xmldsig-more#sha384", typeFromHandle9);
175 dictionary.Add("http://www.w3.org/2001/04/xmldsig-more#hmac-md5", typeFromHandle);
176 dictionary.Add("http://www.w3.org/2001/04/xmldsig-more#hmac-sha256", typeFromHandle3);
177 dictionary.Add("http://www.w3.org/2001/04/xmldsig-more#hmac-sha384", typeFromHandle4);
178 dictionary.Add("http://www.w3.org/2001/04/xmldsig-more#hmac-sha512", typeFromHandle5);
179 dictionary.Add("2.5.29.10", "System.Security.Cryptography.X509Certificates.X509BasicConstraintsExtension, System.Security.Cryptography.X509Certificates");
180 dictionary.Add("2.5.29.19", "System.Security.Cryptography.X509Certificates.X509BasicConstraintsExtension, System.Security.Cryptography.X509Certificates");
181 dictionary.Add("2.5.29.14", "System.Security.Cryptography.X509Certificates.X509SubjectKeyIdentifierExtension, System.Security.Cryptography.X509Certificates");
182 dictionary.Add("2.5.29.15", "System.Security.Cryptography.X509Certificates.X509KeyUsageExtension, System.Security.Cryptography.X509Certificates");
183 dictionary.Add("2.5.29.37", "System.Security.Cryptography.X509Certificates.X509EnhancedKeyUsageExtension, System.Security.Cryptography.X509Certificates");
184 dictionary.Add("X509Chain", "System.Security.Cryptography.X509Certificates.X509Chain, System.Security.Cryptography.X509Certificates");
185 dictionary.Add("1.2.840.113549.1.9.3", "System.Security.Cryptography.Pkcs.Pkcs9ContentType, System.Security.Cryptography.Pkcs");
186 dictionary.Add("1.2.840.113549.1.9.4", "System.Security.Cryptography.Pkcs.Pkcs9MessageDigest, System.Security.Cryptography.Pkcs");
187 dictionary.Add("1.2.840.113549.1.9.5", "System.Security.Cryptography.Pkcs.Pkcs9SigningTime, System.Security.Cryptography.Pkcs");
188 dictionary.Add("1.3.6.1.4.1.311.88.2.1", "System.Security.Cryptography.Pkcs.Pkcs9DocumentName, System.Security.Cryptography.Pkcs");
189 dictionary.Add("1.3.6.1.4.1.311.88.2.2", "System.Security.Cryptography.Pkcs.Pkcs9DocumentDescription, System.Security.Cryptography.Pkcs");
191 return s_defaultNameHT;
192 }
193 }
194
195 [UnsupportedOSPlatform("browser")]
196 public static void AddAlgorithm(Type algorithm, params string[] names)
197 {
198 if (algorithm == null)
199 {
200 throw new ArgumentNullException("algorithm");
201 }
202 if (!algorithm.IsVisible)
203 {
205 }
206 if (names == null)
207 {
208 throw new ArgumentNullException("names");
209 }
210 string[] array = new string[names.Length];
211 Array.Copy(names, array, array.Length);
212 string[] array2 = array;
213 foreach (string value in array2)
214 {
215 if (string.IsNullOrEmpty(value))
216 {
218 }
219 }
220 string[] array3 = array;
221 foreach (string key in array3)
222 {
224 }
225 }
226
227 [RequiresUnreferencedCode("The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.")]
228 public static object? CreateFromName(string name, params object?[]? args)
229 {
230 if (name == null)
231 {
232 throw new ArgumentNullException("name");
233 }
234 appNameHT.TryGetValue(name, out var value);
235 if (value == null && DefaultNameHT.TryGetValue(name, out object value2))
236 {
238 if (value == null && value2 is string typeName)
239 {
240 value = Type.GetType(typeName, throwOnError: false, ignoreCase: false);
241 if (value != null && !value.IsVisible)
242 {
243 value = null;
244 }
245 if (value != null)
246 {
247 appNameHT[name] = value;
248 }
249 }
250 }
251 if (value == null && (args == null || args.Length == 1) && name == "ECDsa")
252 {
253 return ECDsa.Create();
254 }
255 if (value == null)
256 {
257 value = Type.GetType(name, throwOnError: false, ignoreCase: false);
258 if (value != null && !value.IsVisible)
259 {
260 value = null;
261 }
262 }
263 if (value == null)
264 {
265 return null;
266 }
267 MethodBase[] constructors = value.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance);
269 if (array == null)
270 {
271 return null;
272 }
273 if (args == null)
274 {
275 args = Array.Empty<object>();
276 }
278 foreach (MethodBase methodBase in array)
279 {
280 if (methodBase.GetParameters().Length == args.Length)
281 {
282 list.Add(methodBase);
283 }
284 }
285 if (list.Count == 0)
286 {
287 return null;
288 }
289 array = list.ToArray();
290 object state;
291 ConstructorInfo constructorInfo = Type.DefaultBinder.BindToMethod(BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, array, ref args, null, null, null, out state) as ConstructorInfo;
292 if (constructorInfo == null || typeof(Delegate).IsAssignableFrom(constructorInfo.DeclaringType))
293 {
294 return null;
295 }
296 object result = constructorInfo.Invoke(BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, Type.DefaultBinder, args, null);
297 if (state != null)
298 {
299 Type.DefaultBinder.ReorderArgumentArray(ref args, state);
300 }
301 return result;
302 }
303
304 [RequiresUnreferencedCode("The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.")]
305 public static object? CreateFromName(string name)
306 {
307 return CreateFromName(name, null);
308 }
309
310 [UnsupportedOSPlatform("browser")]
311 public static void AddOID(string oid, params string[] names)
312 {
313 if (oid == null)
314 {
315 throw new ArgumentNullException("oid");
316 }
317 if (names == null)
318 {
319 throw new ArgumentNullException("names");
320 }
321 string[] array = new string[names.Length];
322 Array.Copy(names, array, array.Length);
323 string[] array2 = array;
324 foreach (string value in array2)
325 {
326 if (string.IsNullOrEmpty(value))
327 {
329 }
330 }
331 string[] array3 = array;
332 foreach (string key in array3)
333 {
334 appOidHT[key] = oid;
335 }
336 }
337
338 [UnsupportedOSPlatform("browser")]
339 public static string? MapNameToOID(string name)
340 {
341 if (name == null)
342 {
343 throw new ArgumentNullException("name");
344 }
345 appOidHT.TryGetValue(name, out var value);
346 if (string.IsNullOrEmpty(value) && !DefaultOidHT.TryGetValue(name, out value))
347 {
348 try
349 {
350 Oid oid = Oid.FromFriendlyName(name, OidGroup.All);
351 value = oid.Value;
352 return value;
353 }
355 {
356 }
357 }
358 return value;
359 }
360
361 [UnsupportedOSPlatform("browser")]
362 [Obsolete("EncodeOID is obsolete. Use the ASN.1 functionality provided in System.Formats.Asn1.", DiagnosticId = "SYSLIB0031", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
363 public static byte[] EncodeOID(string str)
364 {
365 if (str == null)
366 {
367 throw new ArgumentNullException("str");
368 }
369 string[] array = str.Split('.');
370 uint[] array2 = new uint[array.Length];
371 for (int i = 0; i < array.Length; i++)
372 {
373 array2[i] = (uint)int.Parse(array[i], CultureInfo.InvariantCulture);
374 }
375 if (array2.Length < 2)
376 {
378 }
379 uint value = array2[0] * 40 + array2[1];
380 int index = 2;
382 for (int j = 2; j < array2.Length; j++)
383 {
385 }
386 byte[] array3 = new byte[index];
387 int index2 = 2;
389 for (int k = 2; k < array2.Length; k++)
390 {
392 }
393 if (index2 - 2 > 127)
394 {
396 }
397 array3[0] = 6;
398 array3[1] = (byte)(index2 - 2);
399 return array3;
400 }
401
402 private static void EncodeSingleOidNum(uint value, byte[] destination, ref int index)
403 {
404 if ((int)value < 128)
405 {
406 if (destination != null)
407 {
408 destination[index++] = (byte)value;
409 }
410 else
411 {
412 index++;
413 }
414 }
415 else if (value < 16384)
416 {
417 if (destination != null)
418 {
419 destination[index++] = (byte)((value >> 7) | 0x80u);
420 destination[index++] = (byte)(value & 0x7Fu);
421 }
422 else
423 {
424 index += 2;
425 }
426 }
427 else if (value < 2097152)
428 {
429 if (destination != null)
430 {
431 destination[index++] = (byte)((value >> 14) | 0x80u);
432 destination[index++] = (byte)((value >> 7) | 0x80u);
433 destination[index++] = (byte)(value & 0x7Fu);
434 }
435 else
436 {
437 index += 3;
438 }
439 }
440 else if (value < 268435456)
441 {
442 if (destination != null)
443 {
444 destination[index++] = (byte)((value >> 21) | 0x80u);
445 destination[index++] = (byte)((value >> 14) | 0x80u);
446 destination[index++] = (byte)((value >> 7) | 0x80u);
447 destination[index++] = (byte)(value & 0x7Fu);
448 }
449 else
450 {
451 index += 4;
452 }
453 }
454 else if (destination != null)
455 {
456 destination[index++] = (byte)((value >> 28) | 0x80u);
457 destination[index++] = (byte)((value >> 21) | 0x80u);
458 destination[index++] = (byte)((value >> 14) | 0x80u);
459 destination[index++] = (byte)((value >> 7) | 0x80u);
460 destination[index++] = (byte)(value & 0x7Fu);
461 }
462 else
463 {
464 index += 5;
465 }
466 }
467}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
void Add(TKey key, TValue value)
static CultureInfo InvariantCulture
static string Cryptography_AlgorithmTypesMustBeVisible
Definition SR.cs:166
static string Cryptography_InvalidOID
Definition SR.cs:62
static string Cryptography_Config_EncodedOIDError
Definition SR.cs:46
static string Cryptography_AddNullOrEmptyName
Definition SR.cs:168
Definition SR.cs:7
static volatile Dictionary< string, object > s_defaultNameHT
static Dictionary< string, object > DefaultNameHT
static void AddOID(string oid, params string[] names)
static readonly ConcurrentDictionary< string, Type > appNameHT
static ? object CreateFromName(string name)
static void AddAlgorithm(Type algorithm, params string[] names)
static volatile Dictionary< string, string > s_defaultOidHT
static ? string MapNameToOID(string name)
static ? object CreateFromName(string name, params object?[]? args)
static Dictionary< string, string > DefaultOidHT
static void EncodeSingleOidNum(uint value, byte[] destination, ref int index)
static readonly ConcurrentDictionary< string, string > appOidHT
static new? ECDsa Create(string algorithm)
Definition ECDsa.cs:20
static Oid FromFriendlyName(string friendlyName, OidGroup group)
Definition Oid.cs:106
static StringComparer OrdinalIgnoreCase
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
static Binder DefaultBinder
Definition Type.cs:298