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

◆ Pkcs12PbeDecrypt() [2/2]

static int System.Security.Cryptography.PasswordBasedEncryption.Pkcs12PbeDecrypt ( System::Security::Cryptography::Asn1::AlgorithmIdentifierAsn algorithmIdentifier,
ReadOnlySpan< char > password,
HashAlgorithmName hashAlgorithm,
SymmetricAlgorithm cipher,
ReadOnlySpan< byte > encryptedData,
Span< byte > destination )
inlinestaticprivate

Definition at line 531 of file PasswordBasedEncryption.cs.

532 {
533 if (!algorithmIdentifier.Parameters.HasValue)
534 {
535 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
536 }
537 if (cipher.KeySize > 256 || cipher.BlockSize > 256)
538 {
539 throw new CryptographicException();
540 }
542 int iterationCount = NormalizeIterationCount(pBEParameter.IterationCount, 600000);
543 Span<byte> span = stackalloc byte[cipher.BlockSize / 8];
544 Span<byte> span2 = stackalloc byte[cipher.KeySize / 8];
545 ReadOnlySpan<byte> span3 = pBEParameter.Salt.Span;
546 try
547 {
548 System.Security.Cryptography.Pkcs.Pkcs12Kdf.DeriveIV(password, hashAlgorithm, iterationCount, span3, span);
549 System.Security.Cryptography.Pkcs.Pkcs12Kdf.DeriveCipherKey(password, hashAlgorithm, iterationCount, span3, span2);
550 return Decrypt(cipher, span2, span, encryptedData, destination);
551 }
552 finally
553 {
554 CryptographicOperations.ZeroMemory(span2);
555 CryptographicOperations.ZeroMemory(span);
556 }
557 }
static string Cryptography_Der_Invalid_Encoding
Definition SR.cs:50
Definition SR.cs:7
static int NormalizeIterationCount(int iterationCount, int? iterationLimit=null)
static unsafe int Decrypt(in AlgorithmIdentifierAsn algorithmIdentifier, ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > encryptedData, Span< byte > destination)
static void DeriveCipherKey(ReadOnlySpan< char > password, HashAlgorithmName hashAlgorithm, int iterationCount, ReadOnlySpan< byte > salt, Span< byte > destination)
Definition Pkcs12Kdf.cs:16
static void DeriveIV(ReadOnlySpan< char > password, HashAlgorithmName hashAlgorithm, int iterationCount, ReadOnlySpan< byte > salt, Span< byte > destination)
Definition Pkcs12Kdf.cs:21
unsafe ReadOnlySpan< T > Span
static PBEParameter Decode(ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)

References System.Security.Cryptography.SymmetricAlgorithm.BlockSize, System.SR.Cryptography_Der_Invalid_Encoding, System.Security.Cryptography.Asn1.PBEParameter.Decode(), System.Security.Cryptography.PasswordBasedEncryption.Decrypt(), System.Security.Cryptography.Pkcs.Pkcs12Kdf.DeriveCipherKey(), System.Security.Cryptography.Pkcs.Pkcs12Kdf.DeriveIV(), System.destination, System.Security.Cryptography.Asn1.PBEParameter.IterationCount, System.Security.Cryptography.SymmetricAlgorithm.KeySize, System.Security.Cryptography.PasswordBasedEncryption.NormalizeIterationCount(), System.Security.Cryptography.Asn1.PBEParameter.Salt, System.ReadOnlyMemory< T >.Span, and System.Security.Cryptography.CryptographicOperations.ZeroMemory().