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

◆ Pbes2Decrypt() [2/4]

static unsafe int System.Security.Cryptography.PasswordBasedEncryption.Pbes2Decrypt ( ReadOnlyMemory< byte >? algorithmParameters,
ReadOnlySpan< byte > password,
ReadOnlySpan< byte > encryptedData,
Span< byte > destination )
inlinestaticprivate

Definition at line 324 of file PasswordBasedEncryption.cs.

325 {
326 if (!algorithmParameters.HasValue)
327 {
328 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
329 }
331 if (pBES2Params.KeyDerivationFunc.Algorithm != "1.2.840.113549.1.5.12")
332 {
333 throw new CryptographicException(System.SR.Format(System.SR.Cryptography_UnknownAlgorithmIdentifier, pBES2Params.EncryptionScheme.Algorithm));
334 }
335 int? requestedKeyLength;
336 Rfc2898DeriveBytes rfc2898DeriveBytes = OpenPbkdf2(password, pBES2Params.KeyDerivationFunc.Parameters, out requestedKeyLength);
337 using (rfc2898DeriveBytes)
338 {
339 Span<byte> iv = stackalloc byte[16];
340 SymmetricAlgorithm symmetricAlgorithm = OpenCipher(pBES2Params.EncryptionScheme, requestedKeyLength, ref iv);
341 using (symmetricAlgorithm)
342 {
343 byte[] bytes = rfc2898DeriveBytes.GetBytes(symmetricAlgorithm.KeySize / 8);
344 fixed (byte* ptr = bytes)
345 {
346 try
347 {
348 return Decrypt(symmetricAlgorithm, bytes, iv, encryptedData, destination);
349 }
350 finally
351 {
352 CryptographicOperations.ZeroMemory(bytes);
353 }
354 }
355 }
356 }
357 }
static string Cryptography_Der_Invalid_Encoding
Definition SR.cs:50
static string Cryptography_UnknownAlgorithmIdentifier
Definition SR.cs:150
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7
static SymmetricAlgorithm OpenCipher(AlgorithmIdentifierAsn encryptionScheme, int? requestedKeyLength, ref Span< byte > iv)
static unsafe Rfc2898DeriveBytes OpenPbkdf2(ReadOnlySpan< byte > password, ReadOnlyMemory< byte >? parameters, out int? requestedKeyLength)
static unsafe int Decrypt(in AlgorithmIdentifierAsn algorithmIdentifier, ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > encryptedData, Span< byte > destination)
static PBES2Params Decode(ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)

References System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Algorithm, System.bytes, System.SR.Cryptography_Der_Invalid_Encoding, System.SR.Cryptography_UnknownAlgorithmIdentifier, System.Security.Cryptography.Asn1.PBES2Params.Decode(), System.Security.Cryptography.PasswordBasedEncryption.Decrypt(), System.destination, System.Security.Cryptography.Asn1.PBES2Params.EncryptionScheme, System.SR.Format(), System.Security.Cryptography.Rfc2898DeriveBytes.GetBytes(), System.Security.Cryptography.Asn1.PBES2Params.KeyDerivationFunc, System.Security.Cryptography.SymmetricAlgorithm.KeySize, System.Security.Cryptography.PasswordBasedEncryption.OpenCipher(), System.Security.Cryptography.PasswordBasedEncryption.OpenPbkdf2(), System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Parameters, and System.Security.Cryptography.CryptographicOperations.ZeroMemory().