Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ OpenCipher() [2/2]

static SymmetricAlgorithm System.Security.Cryptography.PasswordBasedEncryption.OpenCipher ( System::Security::Cryptography::Asn1::AlgorithmIdentifierAsn encryptionScheme,
int? requestedKeyLength,
ref Span< byte > iv )
inlinestaticprivate

Definition at line 359 of file PasswordBasedEncryption.cs.

360 {
361 string algorithm = encryptionScheme.Algorithm;
362 switch (algorithm)
363 {
364 case "2.16.840.1.101.3.4.1.2":
365 case "2.16.840.1.101.3.4.1.22":
366 case "2.16.840.1.101.3.4.1.42":
367 {
368 int num = algorithm switch
369 {
370 "2.16.840.1.101.3.4.1.2" => 16,
371 "2.16.840.1.101.3.4.1.22" => 24,
372 "2.16.840.1.101.3.4.1.42" => 32,
373 _ => throw new CryptographicException(),
374 };
375 if (requestedKeyLength.HasValue && requestedKeyLength != num)
376 {
377 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
378 }
379 ReadIvParameter(encryptionScheme.Parameters, 16, ref iv);
380 Aes aes = Aes.Create();
381 aes.KeySize = num * 8;
382 return aes;
383 }
384 case "1.2.840.113549.3.7":
385 if (requestedKeyLength.HasValue && requestedKeyLength != 24)
386 {
387 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
388 }
389 ReadIvParameter(encryptionScheme.Parameters, 8, ref iv);
390 return TripleDES.Create();
391 case "1.2.840.113549.3.2":
392 {
393 if (!encryptionScheme.Parameters.HasValue)
394 {
395 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
396 }
397 if (!requestedKeyLength.HasValue)
398 {
399 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
400 }
402 if (rc2CbcParameters.Iv.Length != 8)
403 {
404 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
405 }
406 RC2 rC = CreateRC2();
407 rC.KeySize = requestedKeyLength.Value * 8;
408 rC.EffectiveKeySize = rc2CbcParameters.GetEffectiveKeyBits();
409 rc2CbcParameters.Iv.Span.CopyTo(iv);
410 iv = iv.Slice(0, rc2CbcParameters.Iv.Length);
411 return rC;
412 }
413 case "1.3.14.3.2.7":
414 if (requestedKeyLength.HasValue && requestedKeyLength != 8)
415 {
416 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
417 }
418 ReadIvParameter(encryptionScheme.Parameters, 8, ref iv);
419 return DES.Create();
420 default:
421 throw new CryptographicException(System.SR.Cryptography_UnknownAlgorithmIdentifier, algorithm);
422 }
423 }
static string Cryptography_Der_Invalid_Encoding
Definition SR.cs:50
static string Cryptography_UnknownAlgorithmIdentifier
Definition SR.cs:150
Definition SR.cs:7
static void ReadIvParameter(ReadOnlyMemory< byte >? encryptionSchemeParameters, int length, ref Span< byte > iv)
unsafe ReadOnlySpan< T > Span
static Rc2CbcParameters Decode(ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)

References System.Security.Cryptography.Aes.Create(), System.Security.Cryptography.DES.Create(), System.Security.Cryptography.TripleDES.Create(), System.Security.Cryptography.PasswordBasedEncryption.CreateRC2(), System.SR.Cryptography_Der_Invalid_Encoding, System.SR.Cryptography_UnknownAlgorithmIdentifier, System.Security.Cryptography.Asn1.Rc2CbcParameters.Decode(), System.Security.Cryptography.Asn1.Rc2CbcParameters.GetEffectiveKeyBits(), System.Security.Cryptography.Asn1.Rc2CbcParameters.Iv, System.ReadOnlyMemory< T >.Length, System.Security.Cryptography.PasswordBasedEncryption.ReadIvParameter(), and System.ReadOnlyMemory< T >.Span.