Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RSA.cs
Go to the documentation of this file.
4using System.IO;
8using System.Text;
10
12
13[UnsupportedOSPlatform("browser")]
14public abstract class RSA : AsymmetricAlgorithm
15{
16 public override string? KeyExchangeAlgorithm => "RSA";
17
18 public override string SignatureAlgorithm => "RSA";
19
20 [RequiresUnreferencedCode("The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.")]
21 public new static RSA? Create(string algName)
22 {
23 return (RSA)CryptoConfig.CreateFromName(algName);
24 }
25
26 public static RSA Create(int keySizeInBits)
27 {
28 RSA rSA = Create();
29 try
30 {
31 rSA.KeySize = keySizeInBits;
32 return rSA;
33 }
34 catch
35 {
36 rSA.Dispose();
37 throw;
38 }
39 }
40
41 public static RSA Create(RSAParameters parameters)
42 {
43 RSA rSA = Create();
44 try
45 {
46 rSA.ImportParameters(parameters);
47 return rSA;
48 }
49 catch
50 {
51 rSA.Dispose();
52 throw;
53 }
54 }
55
56 public abstract RSAParameters ExportParameters(bool includePrivateParameters);
57
58 public abstract void ImportParameters(RSAParameters parameters);
59
60 public virtual byte[] Encrypt(byte[] data, RSAEncryptionPadding padding)
61 {
63 }
64
65 public virtual byte[] Decrypt(byte[] data, RSAEncryptionPadding padding)
66 {
68 }
69
70 public virtual byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
71 {
73 }
74
75 public virtual bool VerifyHash(byte[] hash, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
76 {
78 }
79
80 protected virtual byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
81 {
83 }
84
85 protected virtual byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
86 {
88 }
89
90 public virtual bool TryDecrypt(ReadOnlySpan<byte> data, Span<byte> destination, RSAEncryptionPadding padding, out int bytesWritten)
91 {
92 byte[] array = Decrypt(data.ToArray(), padding);
93 if (destination.Length >= array.Length)
94 {
96 bytesWritten = array.Length;
97 return true;
98 }
99 bytesWritten = 0;
100 return false;
101 }
102
103 public virtual bool TryEncrypt(ReadOnlySpan<byte> data, Span<byte> destination, RSAEncryptionPadding padding, out int bytesWritten)
104 {
105 byte[] array = Encrypt(data.ToArray(), padding);
106 if (destination.Length >= array.Length)
107 {
109 bytesWritten = array.Length;
110 return true;
111 }
112 bytesWritten = 0;
113 return false;
114 }
115
116 protected virtual bool TryHashData(ReadOnlySpan<byte> data, Span<byte> destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
117 {
118 byte[] array = ArrayPool<byte>.Shared.Rent(data.Length);
119 byte[] array2;
120 try
121 {
122 data.CopyTo(array);
123 array2 = HashData(array, 0, data.Length, hashAlgorithm);
124 }
125 finally
126 {
127 Array.Clear(array, 0, data.Length);
129 }
130 if (destination.Length >= array2.Length)
131 {
133 bytesWritten = array2.Length;
134 return true;
135 }
136 bytesWritten = 0;
137 return false;
138 }
139
140 public virtual bool TrySignHash(ReadOnlySpan<byte> hash, Span<byte> destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
141 {
142 byte[] array = SignHash(hash.ToArray(), hashAlgorithm, padding);
143 if (destination.Length >= array.Length)
144 {
146 bytesWritten = array.Length;
147 return true;
148 }
149 bytesWritten = 0;
150 return false;
151 }
152
153 public virtual bool VerifyHash(ReadOnlySpan<byte> hash, ReadOnlySpan<byte> signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
154 {
155 return VerifyHash(hash.ToArray(), signature.ToArray(), hashAlgorithm, padding);
156 }
157
162
163 public virtual byte[] DecryptValue(byte[] rgb)
164 {
166 }
167
168 public virtual byte[] EncryptValue(byte[] rgb)
169 {
171 }
172
173 public byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
174 {
175 if (data == null)
176 {
177 throw new ArgumentNullException("data");
178 }
179 return SignData(data, 0, data.Length, hashAlgorithm, padding);
180 }
181
182 public virtual byte[] SignData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
183 {
184 if (data == null)
185 {
186 throw new ArgumentNullException("data");
187 }
188 if (offset < 0 || offset > data.Length)
189 {
190 throw new ArgumentOutOfRangeException("offset");
191 }
192 if (count < 0 || count > data.Length - offset)
193 {
194 throw new ArgumentOutOfRangeException("count");
195 }
196 if (string.IsNullOrEmpty(hashAlgorithm.Name))
197 {
199 }
200 if (padding == null)
201 {
202 throw new ArgumentNullException("padding");
203 }
204 byte[] hash = HashData(data, offset, count, hashAlgorithm);
205 return SignHash(hash, hashAlgorithm, padding);
206 }
207
208 public virtual byte[] SignData(Stream data, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
209 {
210 if (data == null)
211 {
212 throw new ArgumentNullException("data");
213 }
214 if (string.IsNullOrEmpty(hashAlgorithm.Name))
215 {
217 }
218 if (padding == null)
219 {
220 throw new ArgumentNullException("padding");
221 }
222 byte[] hash = HashData(data, hashAlgorithm);
223 return SignHash(hash, hashAlgorithm, padding);
224 }
225
226 public virtual bool TrySignData(ReadOnlySpan<byte> data, Span<byte> destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
227 {
228 if (string.IsNullOrEmpty(hashAlgorithm.Name))
229 {
231 }
232 if (padding == null)
233 {
234 throw new ArgumentNullException("padding");
235 }
236 if (TryHashData(data, destination, hashAlgorithm, out var bytesWritten2) && TrySignHash(destination.Slice(0, bytesWritten2), destination, hashAlgorithm, padding, out bytesWritten))
237 {
238 return true;
239 }
240 bytesWritten = 0;
241 return false;
242 }
243
244 public bool VerifyData(byte[] data, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
245 {
246 if (data == null)
247 {
248 throw new ArgumentNullException("data");
249 }
250 return VerifyData(data, 0, data.Length, signature, hashAlgorithm, padding);
251 }
252
253 public virtual bool VerifyData(byte[] data, int offset, int count, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
254 {
255 if (data == null)
256 {
257 throw new ArgumentNullException("data");
258 }
259 if (offset < 0 || offset > data.Length)
260 {
261 throw new ArgumentOutOfRangeException("offset");
262 }
263 if (count < 0 || count > data.Length - offset)
264 {
265 throw new ArgumentOutOfRangeException("count");
266 }
267 if (signature == null)
268 {
269 throw new ArgumentNullException("signature");
270 }
271 if (string.IsNullOrEmpty(hashAlgorithm.Name))
272 {
274 }
275 if (padding == null)
276 {
277 throw new ArgumentNullException("padding");
278 }
279 byte[] hash = HashData(data, offset, count, hashAlgorithm);
280 return VerifyHash(hash, signature, hashAlgorithm, padding);
281 }
282
283 public bool VerifyData(Stream data, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
284 {
285 if (data == null)
286 {
287 throw new ArgumentNullException("data");
288 }
289 if (signature == null)
290 {
291 throw new ArgumentNullException("signature");
292 }
293 if (string.IsNullOrEmpty(hashAlgorithm.Name))
294 {
296 }
297 if (padding == null)
298 {
299 throw new ArgumentNullException("padding");
300 }
301 byte[] hash = HashData(data, hashAlgorithm);
302 return VerifyHash(hash, signature, hashAlgorithm, padding);
303 }
304
305 public virtual bool VerifyData(ReadOnlySpan<byte> data, ReadOnlySpan<byte> signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
306 {
307 if (string.IsNullOrEmpty(hashAlgorithm.Name))
308 {
310 }
311 if (padding == null)
312 {
313 throw new ArgumentNullException("padding");
314 }
315 int num = 256;
316 while (true)
317 {
318 int bytesWritten = 0;
320 try
321 {
322 if (TryHashData(data, array, hashAlgorithm, out bytesWritten))
323 {
324 return VerifyHash(new ReadOnlySpan<byte>(array, 0, bytesWritten), signature, hashAlgorithm, padding);
325 }
326 }
327 finally
328 {
330 }
331 num = checked(num * 2);
332 }
333 }
334
335 public virtual byte[] ExportRSAPrivateKey()
336 {
337 AsnWriter asnWriter = WritePkcs1PrivateKey();
338 return asnWriter.Encode();
339 }
340
341 public virtual bool TryExportRSAPrivateKey(Span<byte> destination, out int bytesWritten)
342 {
343 AsnWriter asnWriter = WritePkcs1PrivateKey();
344 return asnWriter.TryEncode(destination, out bytesWritten);
345 }
346
347 public virtual byte[] ExportRSAPublicKey()
348 {
349 AsnWriter asnWriter = WritePkcs1PublicKey();
350 return asnWriter.Encode();
351 }
352
353 public virtual bool TryExportRSAPublicKey(Span<byte> destination, out int bytesWritten)
354 {
355 AsnWriter asnWriter = WritePkcs1PublicKey();
356 return asnWriter.TryEncode(destination, out bytesWritten);
357 }
358
359 public unsafe override bool TryExportSubjectPublicKeyInfo(Span<byte> destination, out int bytesWritten)
360 {
361 int num = KeySize / 4;
362 while (true)
363 {
365 num = array.Length;
366 int bytesWritten2 = 0;
367 fixed (byte* ptr = array)
368 {
369 try
370 {
371 if (!TryExportRSAPublicKey(array, out bytesWritten2))
372 {
373 num = checked(num * 2);
374 continue;
375 }
376 AsnWriter asnWriter = RSAKeyFormatHelper.WriteSubjectPublicKeyInfo(array.AsSpan(0, bytesWritten2));
377 return asnWriter.TryEncode(destination, out bytesWritten);
378 }
379 finally
380 {
382 }
383 }
384 }
385 }
386
387 public override bool TryExportPkcs8PrivateKey(Span<byte> destination, out int bytesWritten)
388 {
389 AsnWriter asnWriter = WritePkcs8PrivateKey();
390 return asnWriter.TryEncode(destination, out bytesWritten);
391 }
392
394 {
395 int num = checked(5 * KeySize) / 8;
396 while (true)
397 {
399 num = array.Length;
400 int bytesWritten = 0;
401 fixed (byte* ptr = array)
402 {
403 try
404 {
405 if (!TryExportRSAPrivateKey(array, out bytesWritten))
406 {
407 num = checked(num * 2);
408 continue;
409 }
411 }
412 finally
413 {
415 }
416 }
417 }
418 }
419
420 public override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<char> password, PbeParameters pbeParameters, Span<byte> destination, out int bytesWritten)
421 {
422 if (pbeParameters == null)
423 {
424 throw new ArgumentNullException("pbeParameters");
425 }
427 AsnWriter pkcs8Writer = WritePkcs8PrivateKey();
428 AsnWriter asnWriter = KeyFormatHelper.WriteEncryptedPkcs8(password, pkcs8Writer, pbeParameters);
429 return asnWriter.TryEncode(destination, out bytesWritten);
430 }
431
432 public override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte> passwordBytes, PbeParameters pbeParameters, Span<byte> destination, out int bytesWritten)
433 {
434 if (pbeParameters == null)
435 {
436 throw new ArgumentNullException("pbeParameters");
437 }
439 AsnWriter pkcs8Writer = WritePkcs8PrivateKey();
440 AsnWriter asnWriter = KeyFormatHelper.WriteEncryptedPkcs8(passwordBytes, pkcs8Writer, pbeParameters);
441 return asnWriter.TryEncode(destination, out bytesWritten);
442 }
443
445 {
446 RSAParameters rsaParameters = ExportParameters(includePrivateParameters: false);
447 return RSAKeyFormatHelper.WritePkcs1PublicKey(in rsaParameters);
448 }
449
451 {
452 RSAParameters rsaParameters = ExportParameters(includePrivateParameters: true);
453 fixed (byte* ptr6 = rsaParameters.D)
454 {
455 fixed (byte* ptr5 = rsaParameters.P)
456 {
457 fixed (byte* ptr4 = rsaParameters.Q)
458 {
459 fixed (byte* ptr3 = rsaParameters.DP)
460 {
461 fixed (byte* ptr2 = rsaParameters.DQ)
462 {
463 fixed (byte* ptr = rsaParameters.InverseQ)
464 {
465 try
466 {
467 return RSAKeyFormatHelper.WritePkcs1PrivateKey(in rsaParameters);
468 }
469 finally
470 {
471 ClearPrivateParameters(in rsaParameters);
472 }
473 }
474 }
475 }
476 }
477 }
478 }
479 }
480
481 public unsafe override void ImportSubjectPublicKeyInfo(ReadOnlySpan<byte> source, out int bytesRead)
482 {
483 fixed (byte* pointer = &MemoryMarshal.GetReference(source))
484 {
485 using MemoryManager<byte> memoryManager = new PointerMemoryManager<byte>(pointer, source.Length);
486 ImportRSAPublicKey(RSAKeyFormatHelper.ReadSubjectPublicKeyInfo(memoryManager.Memory, out var bytesRead2).Span, out var _);
487 bytesRead = bytesRead2;
488 }
489 }
490
491 public unsafe virtual void ImportRSAPublicKey(ReadOnlySpan<byte> source, out int bytesRead)
492 {
493 try
494 {
495 AsnDecoder.ReadEncodedValue(source, AsnEncodingRules.BER, out var _, out var _, out var bytesConsumed);
496 fixed (byte* pointer = &MemoryMarshal.GetReference(source))
497 {
498 using MemoryManager<byte> memoryManager = new PointerMemoryManager<byte>(pointer, bytesConsumed);
500 RSAKeyFormatHelper.ReadRsaPublicKey(memoryManager.Memory, in algId, out var ret);
501 ImportParameters(ret);
502 bytesRead = bytesConsumed;
503 }
504 }
505 catch (AsnContentException inner)
506 {
508 }
509 }
510
511 public unsafe virtual void ImportRSAPrivateKey(ReadOnlySpan<byte> source, out int bytesRead)
512 {
513 try
514 {
515 AsnDecoder.ReadEncodedValue(source, AsnEncodingRules.BER, out var _, out var _, out var bytesConsumed);
516 fixed (byte* pointer = &MemoryMarshal.GetReference(source))
517 {
518 using MemoryManager<byte> memoryManager = new PointerMemoryManager<byte>(pointer, bytesConsumed);
519 ReadOnlyMemory<byte> keyData = memoryManager.Memory;
520 int length = keyData.Length;
522 RSAKeyFormatHelper.FromPkcs1PrivateKey(keyData, in algId, out var ret);
523 fixed (byte* ptr6 = ret.D)
524 {
525 fixed (byte* ptr5 = ret.P)
526 {
527 fixed (byte* ptr4 = ret.Q)
528 {
529 fixed (byte* ptr3 = ret.DP)
530 {
531 fixed (byte* ptr2 = ret.DQ)
532 {
533 fixed (byte* ptr = ret.InverseQ)
534 {
535 try
536 {
537 ImportParameters(ret);
538 }
539 finally
540 {
542 }
543 }
544 }
545 }
546 }
547 }
548 }
549 bytesRead = length;
550 }
551 }
552 catch (AsnContentException inner)
553 {
555 }
556 }
557
558 public unsafe override void ImportPkcs8PrivateKey(ReadOnlySpan<byte> source, out int bytesRead)
559 {
560 fixed (byte* pointer = &MemoryMarshal.GetReference(source))
561 {
562 using MemoryManager<byte> memoryManager = new PointerMemoryManager<byte>(pointer, source.Length);
563 ImportRSAPrivateKey(RSAKeyFormatHelper.ReadPkcs8(memoryManager.Memory, out var bytesRead2).Span, out var _);
564 bytesRead = bytesRead2;
565 }
566 }
567
568 public unsafe override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte> passwordBytes, ReadOnlySpan<byte> source, out int bytesRead)
569 {
570 RSAKeyFormatHelper.ReadEncryptedPkcs8(source, passwordBytes, out var bytesRead2, out var key);
571 fixed (byte* ptr6 = key.D)
572 {
573 fixed (byte* ptr5 = key.P)
574 {
575 fixed (byte* ptr4 = key.Q)
576 {
577 fixed (byte* ptr3 = key.DP)
578 {
579 fixed (byte* ptr2 = key.DQ)
580 {
581 fixed (byte* ptr = key.InverseQ)
582 {
583 try
584 {
586 }
587 finally
588 {
590 }
591 }
592 }
593 }
594 }
595 }
596 }
597 bytesRead = bytesRead2;
598 }
599
600 public unsafe override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<char> password, ReadOnlySpan<byte> source, out int bytesRead)
601 {
602 RSAKeyFormatHelper.ReadEncryptedPkcs8(source, password, out var bytesRead2, out var key);
603 fixed (byte* ptr6 = key.D)
604 {
605 fixed (byte* ptr5 = key.P)
606 {
607 fixed (byte* ptr4 = key.Q)
608 {
609 fixed (byte* ptr3 = key.DP)
610 {
611 fixed (byte* ptr2 = key.DQ)
612 {
613 fixed (byte* ptr = key.InverseQ)
614 {
615 try
616 {
618 }
619 finally
620 {
622 }
623 }
624 }
625 }
626 }
627 }
628 }
629 bytesRead = bytesRead2;
630 }
631
633 {
635 {
636 if (label.SequenceEqual("RSA PRIVATE KEY"))
637 {
638 return ImportRSAPrivateKey;
639 }
640 if (label.SequenceEqual("PRIVATE KEY"))
641 {
642 return ImportPkcs8PrivateKey;
643 }
644 if (label.SequenceEqual("RSA PUBLIC KEY"))
645 {
646 return ImportRSAPublicKey;
647 }
648 return label.SequenceEqual("PUBLIC KEY") ? new PemKeyImportHelpers.ImportKeyAction(ImportSubjectPublicKeyInfo) : null;
649 });
650 }
651
653 {
654 PemKeyImportHelpers.ImportEncryptedPem(input, password, ImportEncryptedPkcs8PrivateKey);
655 }
656
658 {
659 PemKeyImportHelpers.ImportEncryptedPem(input, passwordBytes, ImportEncryptedPkcs8PrivateKey);
660 }
661
662 private static void ClearPrivateParameters(in RSAParameters rsaParameters)
663 {
664 CryptographicOperations.ZeroMemory(rsaParameters.D);
665 CryptographicOperations.ZeroMemory(rsaParameters.P);
666 CryptographicOperations.ZeroMemory(rsaParameters.Q);
667 CryptographicOperations.ZeroMemory(rsaParameters.DP);
668 CryptographicOperations.ZeroMemory(rsaParameters.DQ);
669 CryptographicOperations.ZeroMemory(rsaParameters.InverseQ);
670 }
671
676
677 private static byte[] ReadRequiredElement(ref XmlKeyHelper.ParseState state, string name, int sizeHint = -1)
678 {
679 byte[] array = XmlKeyHelper.ReadCryptoBinary(ref state, name, sizeHint);
680 if (array == null)
681 {
683 }
684 return array;
685 }
686
687 public override void FromXmlString(string xmlString)
688 {
690 byte[] array = ReadRequiredElement(ref state, "Modulus");
691 byte[] exponent = ReadRequiredElement(ref state, "Exponent");
692 int sizeHint = (array.Length + 1) / 2;
693 byte[] p = XmlKeyHelper.ReadCryptoBinary(ref state, "P", sizeHint);
694 byte[] q = XmlKeyHelper.ReadCryptoBinary(ref state, "Q", sizeHint);
695 byte[] dP = XmlKeyHelper.ReadCryptoBinary(ref state, "DP", sizeHint);
696 byte[] dQ = XmlKeyHelper.ReadCryptoBinary(ref state, "DQ", sizeHint);
697 byte[] inverseQ = XmlKeyHelper.ReadCryptoBinary(ref state, "InverseQ", sizeHint);
698 byte[] d = XmlKeyHelper.ReadCryptoBinary(ref state, "D", array.Length);
699 RSAParameters rSAParameters = default(RSAParameters);
700 rSAParameters.Modulus = array;
701 rSAParameters.Exponent = exponent;
702 rSAParameters.D = d;
703 rSAParameters.P = p;
704 rSAParameters.Q = q;
705 rSAParameters.DP = dP;
706 rSAParameters.DQ = dQ;
707 rSAParameters.InverseQ = inverseQ;
708 RSAParameters parameters = rSAParameters;
709 ImportParameters(parameters);
710 }
711
712 public override string ToXmlString(bool includePrivateParameters)
713 {
714 int num = KeySize / 6;
715 int num2 = 100 + num;
716 if (includePrivateParameters)
717 {
718 num2 += 76 + 5 * num / 2;
719 }
720 RSAParameters rSAParameters = ExportParameters(includePrivateParameters);
721 StringBuilder stringBuilder = new StringBuilder(num2);
722 stringBuilder.Append("<RSAKeyValue>");
723 XmlKeyHelper.WriteCryptoBinary("Modulus", rSAParameters.Modulus, stringBuilder);
724 XmlKeyHelper.WriteCryptoBinary("Exponent", rSAParameters.Exponent, stringBuilder);
725 if (includePrivateParameters)
726 {
727 XmlKeyHelper.WriteCryptoBinary("P", rSAParameters.P, stringBuilder);
728 XmlKeyHelper.WriteCryptoBinary("Q", rSAParameters.Q, stringBuilder);
729 XmlKeyHelper.WriteCryptoBinary("DP", rSAParameters.DP, stringBuilder);
730 XmlKeyHelper.WriteCryptoBinary("DQ", rSAParameters.DQ, stringBuilder);
731 XmlKeyHelper.WriteCryptoBinary("InverseQ", rSAParameters.InverseQ, stringBuilder);
732 XmlKeyHelper.WriteCryptoBinary("D", rSAParameters.D, stringBuilder);
733 }
734 stringBuilder.Append("</RSAKeyValue>");
735 return stringBuilder.ToString();
736 }
737
738 public new static RSA Create()
739 {
740 return new RSAImplementation.RSACng();
741 }
742}
static void ImportPem(ReadOnlySpan< char > input, FindImportActionFunc callback)
delegate void ImportKeyAction(ReadOnlySpan< byte > source, out int bytesRead)
static unsafe void Clear(Array array)
Definition Array.cs:755
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
static Asn1Tag ReadEncodedValue(ReadOnlySpan< byte > source, AsnEncodingRules ruleSet, out int contentOffset, out int contentLength, out int bytesConsumed)
Definition AsnDecoder.cs:57
bool TryEncode(Span< byte > destination, out int bytesWritten)
Definition AsnWriter.cs:173
int Encode(Span< byte > destination)
Definition AsnWriter.cs:195
static string Cryptography_Der_Invalid_Encoding
Definition SR.cs:50
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string NotSupported_Method
Definition SR.cs:162
static string Cryptography_InvalidFromXmlString
Definition SR.cs:84
static string Cryptography_HashAlgorithmNameNullOrEmpty
Definition SR.cs:60
static string NotSupported_SubclassOverride
Definition SR.cs:1714
Definition SR.cs:7
static ? object CreateFromName(string name, params object?[]? args)
static void Return(byte[] array, int clearSize=-1)
Definition CryptoPool.cs:12
static byte[] Rent(int minimumLength)
Definition CryptoPool.cs:7
static AsnWriter WriteEncryptedPkcs8(ReadOnlySpan< char > password, AsnWriter pkcs8Writer, PbeParameters pbeParameters)
static void ValidatePbeParameters(PbeParameters pbeParameters, ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes)
static ReadOnlyMemory< byte > ReadSubjectPublicKeyInfo(ReadOnlyMemory< byte > source, out int bytesRead)
static AsnWriter WriteSubjectPublicKeyInfo(ReadOnlySpan< byte > pkcs1PublicKey)
static void FromPkcs1PrivateKey(ReadOnlyMemory< byte > keyData, in AlgorithmIdentifierAsn algId, out RSAParameters ret)
static ReadOnlyMemory< byte > ReadPkcs8(ReadOnlyMemory< byte > source, out int bytesRead)
static AsnWriter WritePkcs1PrivateKey(in RSAParameters rsaParameters)
static void ReadEncryptedPkcs8(ReadOnlySpan< byte > source, ReadOnlySpan< char > password, out int bytesRead, out RSAParameters key)
static AsnWriter WritePkcs1PublicKey(in RSAParameters rsaParameters)
static void ReadRsaPublicKey(ReadOnlyMemory< byte > keyData, in AlgorithmIdentifierAsn algId, out RSAParameters ret)
static AsnWriter WritePkcs8PrivateKey(ReadOnlySpan< byte > pkcs1PrivateKey, AsnWriter copyFrom=null)
static Exception HashAlgorithmNameNullOrEmpty()
Definition RSA.cs:672
override bool TryExportPkcs8PrivateKey(Span< byte > destination, out int bytesWritten)
Definition RSA.cs:387
virtual byte[] SignData(Stream data, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Definition RSA.cs:208
bool VerifyData(Stream data, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Definition RSA.cs:283
unsafe override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, ReadOnlySpan< byte > source, out int bytesRead)
Definition RSA.cs:600
static RSA Create(int keySizeInBits)
Definition RSA.cs:26
virtual bool VerifyHash(ReadOnlySpan< byte > hash, ReadOnlySpan< byte > signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Definition RSA.cs:153
static new? RSA Create(string algName)
Definition RSA.cs:21
virtual byte[] EncryptValue(byte[] rgb)
Definition RSA.cs:168
virtual bool TrySignData(ReadOnlySpan< byte > data, Span< byte > destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
Definition RSA.cs:226
virtual byte[] DecryptValue(byte[] rgb)
Definition RSA.cs:163
virtual byte[] Decrypt(byte[] data, RSAEncryptionPadding padding)
Definition RSA.cs:65
virtual bool TryHashData(ReadOnlySpan< byte > data, Span< byte > destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
Definition RSA.cs:116
virtual bool TryExportRSAPublicKey(Span< byte > destination, out int bytesWritten)
Definition RSA.cs:353
unsafe override void ImportSubjectPublicKeyInfo(ReadOnlySpan< byte > source, out int bytesRead)
Definition RSA.cs:481
override void ImportFromPem(ReadOnlySpan< char > input)
Definition RSA.cs:632
override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
Definition RSA.cs:420
virtual bool VerifyData(ReadOnlySpan< byte > data, ReadOnlySpan< byte > signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Definition RSA.cs:305
override void ImportFromEncryptedPem(ReadOnlySpan< char > input, ReadOnlySpan< byte > passwordBytes)
Definition RSA.cs:657
unsafe override bool TryExportSubjectPublicKeyInfo(Span< byte > destination, out int bytesWritten)
Definition RSA.cs:359
unsafe override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > source, out int bytesRead)
Definition RSA.cs:568
virtual byte[] Encrypt(byte[] data, RSAEncryptionPadding padding)
Definition RSA.cs:60
static new RSA Create()
Definition RSA.cs:738
virtual bool TrySignHash(ReadOnlySpan< byte > hash, Span< byte > destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
Definition RSA.cs:140
virtual bool TryEncrypt(ReadOnlySpan< byte > data, Span< byte > destination, RSAEncryptionPadding padding, out int bytesWritten)
Definition RSA.cs:103
static void ClearPrivateParameters(in RSAParameters rsaParameters)
Definition RSA.cs:662
virtual bool TryExportRSAPrivateKey(Span< byte > destination, out int bytesWritten)
Definition RSA.cs:341
RSAParameters ExportParameters(bool includePrivateParameters)
virtual byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
Definition RSA.cs:80
unsafe override void ImportPkcs8PrivateKey(ReadOnlySpan< byte > source, out int bytesRead)
Definition RSA.cs:558
virtual byte[] ExportRSAPrivateKey()
Definition RSA.cs:335
virtual bool TryDecrypt(ReadOnlySpan< byte > data, Span< byte > destination, RSAEncryptionPadding padding, out int bytesWritten)
Definition RSA.cs:90
virtual unsafe void ImportRSAPublicKey(ReadOnlySpan< byte > source, out int bytesRead)
Definition RSA.cs:491
AsnWriter WritePkcs1PublicKey()
Definition RSA.cs:444
override? string KeyExchangeAlgorithm
Definition RSA.cs:16
virtual byte[] ExportRSAPublicKey()
Definition RSA.cs:347
override void ImportFromEncryptedPem(ReadOnlySpan< char > input, ReadOnlySpan< char > password)
Definition RSA.cs:652
byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Definition RSA.cs:173
static byte[] ReadRequiredElement(ref XmlKeyHelper.ParseState state, string name, int sizeHint=-1)
Definition RSA.cs:677
unsafe AsnWriter WritePkcs8PrivateKey()
Definition RSA.cs:393
static Exception DerivedClassMustOverride()
Definition RSA.cs:158
virtual bool VerifyData(byte[] data, int offset, int count, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Definition RSA.cs:253
virtual byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
Definition RSA.cs:85
bool VerifyData(byte[] data, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Definition RSA.cs:244
override void FromXmlString(string xmlString)
Definition RSA.cs:687
virtual byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Definition RSA.cs:70
override string ToXmlString(bool includePrivateParameters)
Definition RSA.cs:712
virtual bool VerifyHash(byte[] hash, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Definition RSA.cs:75
static RSA Create(RSAParameters parameters)
Definition RSA.cs:41
unsafe AsnWriter WritePkcs1PrivateKey()
Definition RSA.cs:450
void ImportParameters(RSAParameters parameters)
override string SignatureAlgorithm
Definition RSA.cs:18
override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
Definition RSA.cs:432
virtual byte[] SignData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Definition RSA.cs:182
virtual unsafe void ImportRSAPrivateKey(ReadOnlySpan< byte > source, out int bytesRead)
Definition RSA.cs:511
static void WriteCryptoBinary(string name, int value, StringBuilder builder)
static byte[] ReadCryptoBinary(ref ParseState state, string name, int sizeHint=-1)
static ParseState ParseDocument(string xmlString)
override string ToString()
StringBuilder Append(char value, int repeatCount)
void CopyTo(Span< T > destination)