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

◆ OpenPbkdf2() [2/2]

static unsafe Rfc2898DeriveBytes System.Security.Cryptography.PasswordBasedEncryption.OpenPbkdf2 ( ReadOnlySpan< byte > password,
ReadOnlyMemory< byte >? parameters,
out int? requestedKeyLength )
inlinestaticprivate

Definition at line 446 of file PasswordBasedEncryption.cs.

447 {
448 if (!parameters.HasValue)
449 {
450 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
451 }
453 if (pbkdf2Params.Salt.OtherSource.HasValue)
454 {
455 throw new CryptographicException(System.SR.Format(System.SR.Cryptography_UnknownAlgorithmIdentifier, pbkdf2Params.Salt.OtherSource.Value.Algorithm));
456 }
457 if (!pbkdf2Params.Salt.Specified.HasValue)
458 {
459 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
460 }
461 HashAlgorithmName hashAlgorithm = pbkdf2Params.Prf.Algorithm switch
462 {
463 "1.2.840.113549.2.7" => HashAlgorithmName.SHA1,
464 "1.2.840.113549.2.9" => HashAlgorithmName.SHA256,
465 "1.2.840.113549.2.10" => HashAlgorithmName.SHA384,
466 "1.2.840.113549.2.11" => HashAlgorithmName.SHA512,
467 _ => throw new CryptographicException(System.SR.Format(System.SR.Cryptography_UnknownAlgorithmIdentifier, pbkdf2Params.Prf.Algorithm)),
468 };
469 if (!pbkdf2Params.Prf.HasNullEquivalentParameters())
470 {
471 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
472 }
473 int iterations = NormalizeIterationCount(pbkdf2Params.IterationCount);
474 ReadOnlyMemory<byte> value = pbkdf2Params.Salt.Specified.Value;
475 byte[] array = new byte[password.Length];
476 byte[] array2 = new byte[value.Length];
477 fixed (byte* ptr2 = array)
478 {
479 fixed (byte* ptr = array2)
480 {
481 password.CopyTo(array);
482 value.CopyTo(array2);
483 try
484 {
485 requestedKeyLength = pbkdf2Params.KeyLength;
486 return new Rfc2898DeriveBytes(array, array2, iterations, hashAlgorithm);
487 }
488 catch (ArgumentException inner)
489 {
490 throw new CryptographicException(System.SR.Argument_InvalidValue, inner);
491 }
492 finally
493 {
494 CryptographicOperations.ZeroMemory(array);
495 CryptographicOperations.ZeroMemory(array2);
496 }
497 }
498 }
499 }
static string Cryptography_Der_Invalid_Encoding
Definition SR.cs:50
static string Cryptography_UnknownAlgorithmIdentifier
Definition SR.cs:150
static string Argument_InvalidValue
Definition SR.cs:24
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7
static int NormalizeIterationCount(int iterationCount, int? iterationLimit=null)
void CopyTo(Span< T > destination)
static Pbkdf2Params Decode(ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)

References System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Algorithm, System.SR.Argument_InvalidValue, System.array, System.ReadOnlySpan< T >.CopyTo(), System.SR.Cryptography_Der_Invalid_Encoding, System.SR.Cryptography_UnknownAlgorithmIdentifier, System.Security.Cryptography.Asn1.Pbkdf2Params.Decode(), System.SR.Format(), System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.HasNullEquivalentParameters(), System.Security.Cryptography.Asn1.Pbkdf2Params.IterationCount, System.Security.Cryptography.Asn1.Pbkdf2Params.KeyLength, System.ReadOnlySpan< T >.Length, System.Security.Cryptography.PasswordBasedEncryption.NormalizeIterationCount(), System.Security.Cryptography.Asn1.Pbkdf2SaltChoice.OtherSource, System.Security.Cryptography.Asn1.Pbkdf2Params.Prf, System.Security.Cryptography.Asn1.Pbkdf2Params.Salt, System.Security.Cryptography.HashAlgorithmName.SHA1, System.Security.Cryptography.HashAlgorithmName.SHA256, System.Security.Cryptography.HashAlgorithmName.SHA384, System.Security.Cryptography.HashAlgorithmName.SHA512, System.Security.Cryptography.Asn1.Pbkdf2SaltChoice.Specified, System.value, and System.Security.Cryptography.CryptographicOperations.ZeroMemory().