Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PasswordBasedEncryption.cs
Go to the documentation of this file.
5using System.Text;
7
9
10internal static class PasswordBasedEncryption
11{
16
17 internal static void ValidatePbeParameters(PbeParameters pbeParameters, ReadOnlySpan<char> password, ReadOnlySpan<byte> passwordBytes)
18 {
19 PbeEncryptionAlgorithm encryptionAlgorithm = pbeParameters.EncryptionAlgorithm;
20 switch (encryptionAlgorithm)
21 {
22 case PbeEncryptionAlgorithm.Aes128Cbc:
23 case PbeEncryptionAlgorithm.Aes192Cbc:
24 case PbeEncryptionAlgorithm.Aes256Cbc:
25 break;
26 case PbeEncryptionAlgorithm.TripleDes3KeyPkcs12:
27 if (pbeParameters.HashAlgorithm != HashAlgorithmName.SHA1)
28 {
30 }
31 if (passwordBytes.Length > 0 && password.Length == 0)
32 {
33 throw AlgorithmKdfRequiresChars(encryptionAlgorithm.ToString());
34 }
35 break;
36 default:
37 throw new CryptographicException(System.SR.Cryptography_UnknownAlgorithmIdentifier, encryptionAlgorithm.ToString());
38 }
39 }
40
41 internal unsafe static int Decrypt(in System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn algorithmIdentifier, ReadOnlySpan<char> password, ReadOnlySpan<byte> passwordBytes, ReadOnlySpan<byte> encryptedData, Span<byte> destination)
42 {
43 SymmetricAlgorithm symmetricAlgorithm = null;
44 bool flag = false;
45 HashAlgorithmName hashAlgorithm;
46 switch (algorithmIdentifier.Algorithm)
47 {
48 case "1.2.840.113549.1.5.3":
49 hashAlgorithm = HashAlgorithmName.MD5;
50 symmetricAlgorithm = DES.Create();
51 break;
52 case "1.2.840.113549.1.5.6":
53 hashAlgorithm = HashAlgorithmName.MD5;
54 symmetricAlgorithm = CreateRC2();
55 break;
56 case "1.2.840.113549.1.5.10":
57 hashAlgorithm = HashAlgorithmName.SHA1;
58 symmetricAlgorithm = DES.Create();
59 break;
60 case "1.2.840.113549.1.5.11":
61 hashAlgorithm = HashAlgorithmName.SHA1;
62 symmetricAlgorithm = CreateRC2();
63 break;
64 case "1.2.840.113549.1.12.1.3":
65 hashAlgorithm = HashAlgorithmName.SHA1;
66 symmetricAlgorithm = TripleDES.Create();
67 flag = true;
68 break;
69 case "1.2.840.113549.1.12.1.4":
70 hashAlgorithm = HashAlgorithmName.SHA1;
71 symmetricAlgorithm = TripleDES.Create();
72 symmetricAlgorithm.KeySize = 128;
73 flag = true;
74 break;
75 case "1.2.840.113549.1.12.1.5":
76 hashAlgorithm = HashAlgorithmName.SHA1;
77 symmetricAlgorithm = CreateRC2();
78 symmetricAlgorithm.KeySize = 128;
79 flag = true;
80 break;
81 case "1.2.840.113549.1.12.1.6":
82 hashAlgorithm = HashAlgorithmName.SHA1;
83 symmetricAlgorithm = CreateRC2();
84 symmetricAlgorithm.KeySize = 40;
85 flag = true;
86 break;
87 case "1.2.840.113549.1.5.13":
88 return Pbes2Decrypt(algorithmIdentifier.Parameters, password, passwordBytes, encryptedData, destination);
89 default:
91 }
92 using (symmetricAlgorithm)
93 {
94 if (flag)
95 {
96 if (password.IsEmpty && passwordBytes.Length > 0)
97 {
98 throw AlgorithmKdfRequiresChars(algorithmIdentifier.Algorithm);
99 }
100 return Pkcs12PbeDecrypt(algorithmIdentifier, password, hashAlgorithm, symmetricAlgorithm, encryptedData, destination);
101 }
102 using IncrementalHash hasher = IncrementalHash.CreateHash(hashAlgorithm);
103 Span<byte> span = stackalloc byte[128];
104 ReadOnlySpan<byte> password2 = default(Span<byte>);
105 byte[] array = null;
106 Encoding encoding = null;
107 if (passwordBytes.Length > 0 || password.Length == 0)
108 {
109 password2 = passwordBytes;
110 }
111 else
112 {
113 encoding = Encoding.UTF8;
114 int byteCount = encoding.GetByteCount(password);
115 if (byteCount > span.Length)
116 {
118 span = array.AsSpan(0, byteCount);
119 }
120 else
121 {
122 span = span.Slice(0, byteCount);
123 }
124 }
125 fixed (byte* ptr = &MemoryMarshal.GetReference(span))
126 {
127 if (encoding != null)
128 {
129 span = span[..encoding.GetBytes(password, span)];
130 password2 = span;
131 }
132 try
133 {
134 return Pbes1Decrypt(algorithmIdentifier.Parameters, password2, hasher, symmetricAlgorithm, encryptedData, destination);
135 }
136 finally
137 {
139 if (array != null)
140 {
142 }
143 }
144 }
145 }
146 }
147
148 internal static void InitiateEncryption(PbeParameters pbeParameters, out SymmetricAlgorithm cipher, out string hmacOid, out string encryptionAlgorithmOid, out bool isPkcs12)
149 {
150 isPkcs12 = false;
151 switch (pbeParameters.EncryptionAlgorithm)
152 {
153 case PbeEncryptionAlgorithm.Aes128Cbc:
154 cipher = Aes.Create();
155 cipher.KeySize = 128;
156 encryptionAlgorithmOid = "2.16.840.1.101.3.4.1.2";
157 break;
158 case PbeEncryptionAlgorithm.Aes192Cbc:
159 cipher = Aes.Create();
160 cipher.KeySize = 192;
161 encryptionAlgorithmOid = "2.16.840.1.101.3.4.1.22";
162 break;
163 case PbeEncryptionAlgorithm.Aes256Cbc:
164 cipher = Aes.Create();
165 cipher.KeySize = 256;
166 encryptionAlgorithmOid = "2.16.840.1.101.3.4.1.42";
167 break;
168 case PbeEncryptionAlgorithm.TripleDes3KeyPkcs12:
169 cipher = TripleDES.Create();
170 cipher.KeySize = 192;
171 encryptionAlgorithmOid = "1.2.840.113549.1.12.1.3";
172 isPkcs12 = true;
173 break;
174 default:
176 }
177 HashAlgorithmName hashAlgorithm = pbeParameters.HashAlgorithm;
178 if (hashAlgorithm == HashAlgorithmName.SHA256)
179 {
180 hmacOid = "1.2.840.113549.2.9";
181 return;
182 }
183 if (hashAlgorithm == HashAlgorithmName.SHA384)
184 {
185 hmacOid = "1.2.840.113549.2.10";
186 return;
187 }
188 if (hashAlgorithm == HashAlgorithmName.SHA512)
189 {
190 hmacOid = "1.2.840.113549.2.11";
191 return;
192 }
193 if (hashAlgorithm == HashAlgorithmName.SHA1)
194 {
195 hmacOid = "1.2.840.113549.2.7";
196 return;
197 }
198 cipher.Dispose();
200 }
201
202 internal unsafe static int Encrypt(ReadOnlySpan<char> password, ReadOnlySpan<byte> passwordBytes, SymmetricAlgorithm cipher, bool isPkcs12, AsnWriter source, PbeParameters pbeParameters, ReadOnlySpan<byte> salt, byte[] destination, Span<byte> ivDest)
203 {
204 byte[] array = null;
205 byte[] iV = cipher.IV;
206 int encodedLength = source.GetEncodedLength();
207 byte[] array2 = System.Security.Cryptography.CryptoPool.Rent(encodedLength);
208 int num = cipher.KeySize / 8;
209 int iterationCount = pbeParameters.IterationCount;
210 HashAlgorithmName hashAlgorithm = pbeParameters.HashAlgorithm;
211 Encoding uTF = Encoding.UTF8;
212 if (!isPkcs12)
213 {
214 array = ((passwordBytes.Length == 0 && password.Length > 0) ? new byte[uTF.GetByteCount(password)] : ((passwordBytes.Length != 0) ? new byte[passwordBytes.Length] : Array.Empty<byte>()));
215 }
216 fixed (byte* ptr3 = array2)
217 {
218 fixed (byte* ptr2 = array)
219 {
220 byte[] array3;
221 if (isPkcs12)
222 {
223 array3 = new byte[num];
224 System.Security.Cryptography.Pkcs.Pkcs12Kdf.DeriveCipherKey(password, hashAlgorithm, iterationCount, salt, array3);
225 System.Security.Cryptography.Pkcs.Pkcs12Kdf.DeriveIV(password, hashAlgorithm, iterationCount, salt, iV);
226 ivDest.Clear();
227 }
228 else
229 {
230 if (passwordBytes.Length > 0)
231 {
232 passwordBytes.CopyTo(array);
233 }
234 else if (password.Length > 0)
235 {
236 int bytes = uTF.GetBytes(password, array);
237 if (bytes != array.Length)
238 {
239 throw new CryptographicException();
240 }
241 }
242 using (Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(array, salt.ToArray(), iterationCount, hashAlgorithm))
243 {
244 array3 = rfc2898DeriveBytes.GetBytes(num);
245 }
246 iV.CopyTo(ivDest);
247 }
248 fixed (byte* ptr = array3)
249 {
251 using ICryptoTransform cryptoTransform = cipher.CreateEncryptor(array3, iV);
252 int num2 = cipher.BlockSize / 8;
253 int num3 = encodedLength % num2;
254 int num4 = encodedLength - num3;
255 try
256 {
257 if (!source.TryEncode(array2, out var _))
258 {
259 throw new CryptographicException();
260 }
261 int num5 = 0;
262 if (num4 != 0)
263 {
264 num5 = cryptoTransform.TransformBlock(array2, 0, num4, destination, 0);
265 }
266 byte[] array4 = cryptoTransform.TransformFinalBlock(array2, num5, num3);
267 array4.AsSpan().CopyTo(destination.AsSpan(num5));
268 return num5 + array4.Length;
269 }
270 finally
271 {
272 System.Security.Cryptography.CryptoPool.Return(array2, encodedLength);
273 }
274 }
275 }
276 }
277 }
278
279 private unsafe static int Pbes2Decrypt(ReadOnlyMemory<byte>? algorithmParameters, ReadOnlySpan<char> password, ReadOnlySpan<byte> passwordBytes, ReadOnlySpan<byte> encryptedData, Span<byte> destination)
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 }
323
324 private unsafe static int Pbes2Decrypt(ReadOnlyMemory<byte>? algorithmParameters, ReadOnlySpan<byte> password, ReadOnlySpan<byte> encryptedData, Span<byte> destination)
325 {
326 if (!algorithmParameters.HasValue)
327 {
329 }
331 if (pBES2Params.KeyDerivationFunc.Algorithm != "1.2.840.113549.1.5.12")
332 {
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 {
353 }
354 }
355 }
356 }
357 }
358
359 private static SymmetricAlgorithm OpenCipher(System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn encryptionScheme, int? requestedKeyLength, ref Span<byte> iv)
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 {
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 {
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 {
396 }
397 if (!requestedKeyLength.HasValue)
398 {
400 }
402 if (rc2CbcParameters.Iv.Length != 8)
403 {
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 {
417 }
418 ReadIvParameter(encryptionScheme.Parameters, 8, ref iv);
419 return DES.Create();
420 default:
422 }
423 }
424
425 private static void ReadIvParameter(ReadOnlyMemory<byte>? encryptionSchemeParameters, int length, ref Span<byte> iv)
426 {
427 if (!encryptionSchemeParameters.HasValue)
428 {
430 }
431 try
432 {
433 ReadOnlySpan<byte> span = encryptionSchemeParameters.Value.Span;
434 if (!AsnDecoder.TryReadOctetString(span, iv, AsnEncodingRules.BER, out var bytesConsumed, out var bytesWritten) || bytesWritten != length || bytesConsumed != span.Length)
435 {
437 }
438 iv = iv.Slice(0, bytesWritten);
439 }
440 catch (AsnContentException inner)
441 {
443 }
444 }
445
446 private unsafe static Rfc2898DeriveBytes OpenPbkdf2(ReadOnlySpan<byte> password, ReadOnlyMemory<byte>? parameters, out int? requestedKeyLength)
447 {
448 if (!parameters.HasValue)
449 {
451 }
453 if (pbkdf2Params.Salt.OtherSource.HasValue)
454 {
456 }
457 if (!pbkdf2Params.Salt.Specified.HasValue)
458 {
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,
468 };
469 if (!pbkdf2Params.Prf.HasNullEquivalentParameters())
470 {
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 {
491 }
492 finally
493 {
496 }
497 }
498 }
499 }
500
501 private static int Pbes1Decrypt(ReadOnlyMemory<byte>? algorithmParameters, ReadOnlySpan<byte> password, IncrementalHash hasher, SymmetricAlgorithm cipher, ReadOnlySpan<byte> encryptedData, Span<byte> destination)
502 {
503 if (!algorithmParameters.HasValue)
504 {
506 }
508 if (pBEParameter.Salt.Length != 8)
509 {
511 }
512 if (pBEParameter.IterationCount < 1)
513 {
515 }
516 int iterationCount = NormalizeIterationCount(pBEParameter.IterationCount);
517 Span<byte> span = stackalloc byte[16];
518 try
519 {
520 Pbkdf1(hasher, password, pBEParameter.Salt.Span, iterationCount, span);
521 Span<byte> span2 = span.Slice(0, 8);
522 Span<byte> span3 = span.Slice(8, 8);
523 return Decrypt(cipher, span2, span3, encryptedData, destination);
524 }
525 finally
526 {
528 }
529 }
530
532 {
533 if (!algorithmIdentifier.Parameters.HasValue)
534 {
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 {
556 }
557 }
558
560 {
561 byte[] array = new byte[key.Length];
562 byte[] array2 = new byte[iv.Length];
563 byte[] array3 = System.Security.Cryptography.CryptoPool.Rent(encryptedData.Length);
564 byte[] array4 = System.Security.Cryptography.CryptoPool.Rent(destination.Length);
565 fixed (byte* ptr5 = array)
566 {
567 fixed (byte* ptr4 = array2)
568 {
569 fixed (byte* ptr3 = array3)
570 {
571 fixed (byte* ptr2 = array4)
572 {
573 try
574 {
575 key.CopyTo(array);
576 iv.CopyTo(array2);
577 using ICryptoTransform cryptoTransform = cipher.CreateDecryptor(array, array2);
578 encryptedData.CopyTo(array3);
579 int num = cryptoTransform.TransformBlock(array3, 0, encryptedData.Length, array4, 0);
580 array4.AsSpan(0, num).CopyTo(destination);
581 byte[] array5 = cryptoTransform.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
582 fixed (byte* ptr = array5)
583 {
584 Span<byte> buffer = array5.AsSpan();
585 buffer.CopyTo(destination.Slice(num));
587 }
588 return num + array5.Length;
589 }
590 finally
591 {
594 System.Security.Cryptography.CryptoPool.Return(array3, encryptedData.Length);
596 }
597 }
598 }
599 }
600 }
601 }
602
603 private static void Pbkdf1(IncrementalHash hasher, ReadOnlySpan<byte> password, ReadOnlySpan<byte> salt, int iterationCount, Span<byte> dk)
604 {
605 Span<byte> span = stackalloc byte[20];
606 hasher.AppendData(password);
607 hasher.AppendData(salt);
608 if (!hasher.TryGetHashAndReset(span, out var bytesWritten))
609 {
610 throw new CryptographicException();
611 }
612 span = span.Slice(0, bytesWritten);
613 for (int i = 1; i < iterationCount; i++)
614 {
615 hasher.AppendData(span);
616 if (!hasher.TryGetHashAndReset(span, out bytesWritten) || bytesWritten != span.Length)
617 {
618 throw new CryptographicException();
619 }
620 }
621 span.Slice(0, dk.Length).CopyTo(dk);
623 }
624
625 internal static void WritePbeAlgorithmIdentifier(AsnWriter writer, bool isPkcs12, string encryptionAlgorithmOid, Span<byte> salt, int iterationCount, string hmacOid, Span<byte> iv)
626 {
627 writer.PushSequence();
628 if (isPkcs12)
629 {
630 writer.WriteObjectIdentifierForCrypto(encryptionAlgorithmOid);
631 writer.PushSequence();
632 writer.WriteOctetString(salt);
633 writer.WriteInteger((long)iterationCount, (Asn1Tag?)null);
634 writer.PopSequence();
635 }
636 else
637 {
638 writer.WriteObjectIdentifierForCrypto("1.2.840.113549.1.5.13");
639 writer.PushSequence();
640 writer.PushSequence();
641 writer.WriteObjectIdentifierForCrypto("1.2.840.113549.1.5.12");
642 writer.PushSequence();
643 writer.WriteOctetString(salt);
644 writer.WriteInteger((long)iterationCount, (Asn1Tag?)null);
645 if (hmacOid != "1.2.840.113549.2.7")
646 {
647 writer.PushSequence();
648 writer.WriteObjectIdentifierForCrypto(hmacOid);
649 writer.WriteNull();
650 writer.PopSequence();
651 }
652 writer.PopSequence();
653 writer.PopSequence();
654 writer.PushSequence();
655 writer.WriteObjectIdentifierForCrypto(encryptionAlgorithmOid);
656 writer.WriteOctetString(iv);
657 writer.PopSequence();
658 writer.PopSequence();
659 }
660 writer.PopSequence();
661 }
662
663 internal static int NormalizeIterationCount(int iterationCount, int? iterationLimit = null)
664 {
665 if (iterationCount <= 0 || (iterationLimit.HasValue && iterationCount > iterationLimit.Value))
666 {
668 }
669 return iterationCount;
670 }
671
672 private static RC2 CreateRC2()
673 {
675 {
677 }
678 return RC2.Create();
679 }
680}
static bool TryReadOctetString(ReadOnlySpan< byte > source, Span< byte > destination, AsnEncodingRules ruleSet, out int bytesConsumed, out int bytesWritten, Asn1Tag? expectedTag=null)
static string Cryptography_Der_Invalid_Encoding
Definition SR.cs:50
static string Cryptography_AlgorithmNotSupported
Definition SR.cs:38
static string Cryptography_UnknownAlgorithmIdentifier
Definition SR.cs:150
static string Cryptography_UnknownHashAlgorithm
Definition SR.cs:152
static string Cryptography_AlgKdfRequiresChars
Definition SR.cs:36
static string Argument_InvalidValue
Definition SR.cs:24
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7
static new Aes Create()
Definition Aes.cs:30
static void Return(byte[] array, int clearSize=-1)
Definition CryptoPool.cs:12
static byte[] Rent(int minimumLength)
Definition CryptoPool.cs:7
static new DES Create()
Definition DES.cs:66
static IncrementalHash CreateHash(HashAlgorithmName hashAlgorithm)
bool TryGetHashAndReset(Span< byte > destination, out int bytesWritten)
static SymmetricAlgorithm OpenCipher(System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn encryptionScheme, int? requestedKeyLength, ref Span< byte > iv)
static int Pbes1Decrypt(ReadOnlyMemory< byte >? algorithmParameters, ReadOnlySpan< byte > password, IncrementalHash hasher, SymmetricAlgorithm cipher, ReadOnlySpan< byte > encryptedData, Span< byte > destination)
static void InitiateEncryption(PbeParameters pbeParameters, out SymmetricAlgorithm cipher, out string hmacOid, out string encryptionAlgorithmOid, out bool isPkcs12)
static void ReadIvParameter(ReadOnlyMemory< byte >? encryptionSchemeParameters, int length, ref Span< byte > iv)
static unsafe int Encrypt(ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes, SymmetricAlgorithm cipher, bool isPkcs12, AsnWriter source, PbeParameters pbeParameters, ReadOnlySpan< byte > salt, byte[] destination, Span< byte > ivDest)
static unsafe int Pbes2Decrypt(ReadOnlyMemory< byte >? algorithmParameters, ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > encryptedData, Span< byte > destination)
static SymmetricAlgorithm OpenCipher(AlgorithmIdentifierAsn encryptionScheme, int? requestedKeyLength, ref Span< byte > iv)
static int Pkcs12PbeDecrypt(AlgorithmIdentifierAsn algorithmIdentifier, ReadOnlySpan< char > password, HashAlgorithmName hashAlgorithm, SymmetricAlgorithm cipher, ReadOnlySpan< byte > encryptedData, Span< byte > destination)
static int NormalizeIterationCount(int iterationCount, int? iterationLimit=null)
static CryptographicException AlgorithmKdfRequiresChars(string algId)
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 void Pbkdf1(IncrementalHash hasher, ReadOnlySpan< byte > password, ReadOnlySpan< byte > salt, int iterationCount, Span< byte > dk)
static int Pkcs12PbeDecrypt(System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn algorithmIdentifier, ReadOnlySpan< char > password, HashAlgorithmName hashAlgorithm, SymmetricAlgorithm cipher, ReadOnlySpan< byte > encryptedData, Span< byte > destination)
static void WritePbeAlgorithmIdentifier(AsnWriter writer, bool isPkcs12, string encryptionAlgorithmOid, Span< byte > salt, int iterationCount, string hmacOid, Span< byte > iv)
static unsafe int Decrypt(in System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn algorithmIdentifier, ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > encryptedData, Span< byte > destination)
static unsafe int Decrypt(SymmetricAlgorithm cipher, ReadOnlySpan< byte > key, ReadOnlySpan< byte > iv, ReadOnlySpan< byte > encryptedData, Span< byte > destination)
static unsafe int Pbes2Decrypt(ReadOnlyMemory< byte >? algorithmParameters, ReadOnlySpan< byte > password, ReadOnlySpan< byte > encryptedData, Span< byte > destination)
static void ValidatePbeParameters(PbeParameters pbeParameters, ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes)
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
static new RC2 Create()
Definition RC2.cs:84
static new TripleDES Create()
Definition TripleDES.cs:59
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
unsafe ReadOnlySpan< T > Span
void CopyTo(Span< T > destination)
static PBEParameter Decode(ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)
static PBES2Params Decode(ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)
static Pbkdf2Params Decode(ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)
static Rc2CbcParameters Decode(ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)
Span< T > Slice(int start)
Definition Span.cs:271
unsafe void Clear()
Definition Span.cs:198
int Length
Definition Span.cs:70