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

◆ Pbes2Decrypt() [4/4]

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

Definition at line 279 of file PasswordBasedEncryption.cs.

280 {
281 Span<byte> span = stackalloc byte[128];
282 ReadOnlySpan<byte> password2 = default(Span<byte>);
283 byte[] array = null;
284 Encoding encoding = null;
285 if (passwordBytes.Length > 0 || password.Length == 0)
286 {
287 password2 = passwordBytes;
288 }
289 else
290 {
291 encoding = Encoding.UTF8;
292 int byteCount = encoding.GetByteCount(password);
293 if (byteCount > span.Length)
294 {
296 span = array.AsSpan(0, byteCount);
297 }
298 else
299 {
300 span = span.Slice(0, byteCount);
301 }
302 }
303 fixed (byte* ptr = &MemoryMarshal.GetReference(span))
304 {
305 if (encoding != null)
306 {
307 span = span[..encoding.GetBytes(password, span)];
308 password2 = span;
309 }
310 try
311 {
312 return Pbes2Decrypt(algorithmParameters, password2, encryptedData, destination);
313 }
314 finally
315 {
316 if (array != null)
317 {
319 }
320 }
321 }
322 }
static void Return(byte[] array, int clearSize=-1)
Definition CryptoPool.cs:12
static byte[] Rent(int minimumLength)
Definition CryptoPool.cs:7
static unsafe int Pbes2Decrypt(ReadOnlyMemory< byte >? algorithmParameters, ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > encryptedData, Span< byte > destination)
static Encoding UTF8
Definition Encoding.cs:526
virtual byte[] GetBytes(char[] chars)
Definition Encoding.cs:781
virtual int GetByteCount(char[] chars)
Definition Encoding.cs:713

References System.array, System.byteCount, System.destination, System.Text.Encoding.GetByteCount(), System.Text.Encoding.GetBytes(), System.ReadOnlySpan< T >.Length, System.Span< T >.Length, System.Security.Cryptography.PasswordBasedEncryption.Pbes2Decrypt(), System.Security.Cryptography.CryptoPool.Rent(), System.Security.Cryptography.CryptoPool.Return(), System.Span< T >.Slice(), and System.Text.Encoding.UTF8.