Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RSAImplementation.cs
Go to the documentation of this file.
3using System.IO;
7
9
10internal static class RSAImplementation
11{
12 public sealed class RSACng : RSA
13 {
15
16 private int _lastKeySize;
17
18 private bool _disposed;
19
21 {
25 });
26
27 public override KeySizes[] LegalKeySizes => new KeySizes[1]
28 {
29 new KeySizes(512, 16384, 64)
30 };
31
32 private void ThrowIfDisposed()
33 {
34 if (_disposed)
35 {
36 throw new ObjectDisposedException("RSA");
37 }
38 }
39
55
57 {
58 string blobType = (includePrivateParameters ? "RSAFULLPRIVATEBLOB" : "RSAPUBLICBLOB");
61 }
62
68
74
75 private void ImportKeyBlob(byte[] rsaBlob, bool includePrivate)
76 {
78 string blobType = (includePrivate ? "RSAPRIVATEBLOB" : "RSAPUBLICBLOB");
81 }
82
89
97
98 protected override void Dispose(bool disposing)
99 {
100 if (disposing)
101 {
103 _keyHandle = null;
104 _disposed = true;
105 }
106 base.Dispose(disposing);
107 }
108
109 public RSACng()
110 : this(2048)
111 {
112 }
113
114 public RSACng(int keySize)
115 {
117 }
118
119 protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
120 {
121 return CngCommon.HashData(data, offset, count, hashAlgorithm);
122 }
123
124 protected override bool TryHashData(ReadOnlySpan<byte> data, Span<byte> destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
125 {
126 return CngCommon.TryHashData(data, destination, hashAlgorithm, out bytesWritten);
127 }
128
129 protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
130 {
131 return CngCommon.HashData(data, hashAlgorithm);
132 }
133
134 private void ForceSetKeySize(int newKeySize)
135 {
137 }
138
139 public override byte[] Encrypt(byte[] data, RSAEncryptionPadding padding)
140 {
141 return EncryptOrDecrypt(data, padding, encrypt: true);
142 }
143
144 public override byte[] Decrypt(byte[] data, RSAEncryptionPadding padding)
145 {
146 return EncryptOrDecrypt(data, padding, encrypt: false);
147 }
148
150 {
151 return TryEncryptOrDecrypt(data, destination, padding, encrypt: true, out bytesWritten);
152 }
153
155 {
156 return TryEncryptOrDecrypt(data, destination, padding, encrypt: false, out bytesWritten);
157 }
158
159 private unsafe byte[] EncryptOrDecrypt(byte[] data, RSAEncryptionPadding padding, bool encrypt)
160 {
161 if (data == null)
162 {
163 throw new ArgumentNullException("data");
164 }
165 if (padding == null)
166 {
167 throw new ArgumentNullException("padding");
168 }
170 if (!encrypt && data.Length != num)
171 {
173 }
174 if (encrypt && padding.Mode == RSAEncryptionPaddingMode.Pkcs1 && data.Length > num - 11)
175 {
177 }
179 if (encrypt && data.Length == 0)
180 {
182 Span<byte> span = new Span<byte>(array, 0, num);
183 try
184 {
185 if (padding == RSAEncryptionPadding.Pkcs1)
186 {
188 }
189 else
190 {
191 if (padding.Mode != RSAEncryptionPaddingMode.Oaep)
192 {
194 }
196 rsaPaddingProcessor.PadOaep(data, span);
197 }
198 return EncryptOrDecrypt(key, span, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_NO_PADDING_FLAG, null, encrypt);
199 }
200 finally
201 {
204 }
205 }
206 switch (padding.Mode)
207 {
208 case RSAEncryptionPaddingMode.Pkcs1:
209 return EncryptOrDecrypt(key, data, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PKCS1_FLAG, null, encrypt);
210 case RSAEncryptionPaddingMode.Oaep:
211 {
213 try
214 {
215 global::Interop.BCrypt.BCRYPT_OAEP_PADDING_INFO bCRYPT_OAEP_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_OAEP_PADDING_INFO);
216 bCRYPT_OAEP_PADDING_INFO.pszAlgId = intPtr;
217 bCRYPT_OAEP_PADDING_INFO.pbLabel = IntPtr.Zero;
218 bCRYPT_OAEP_PADDING_INFO.cbLabel = 0;
219 global::Interop.BCrypt.BCRYPT_OAEP_PADDING_INFO bCRYPT_OAEP_PADDING_INFO2 = bCRYPT_OAEP_PADDING_INFO;
220 return EncryptOrDecrypt(key, data, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_OAEP_FLAG, &bCRYPT_OAEP_PADDING_INFO2, encrypt);
221 }
222 finally
223 {
225 }
226 }
227 default:
229 }
230 }
231
233 {
234 if (padding == null)
235 {
236 throw new ArgumentNullException("padding");
237 }
239 if (!encrypt && data.Length != num)
240 {
242 }
243 if (encrypt && padding.Mode == RSAEncryptionPaddingMode.Pkcs1 && data.Length > num - 11)
244 {
246 }
248 if (encrypt && data.Length == 0)
249 {
251 Span<byte> span = new Span<byte>(array, 0, num);
252 try
253 {
254 if (padding == RSAEncryptionPadding.Pkcs1)
255 {
257 }
258 else
259 {
260 if (padding.Mode != RSAEncryptionPaddingMode.Oaep)
261 {
263 }
265 rsaPaddingProcessor.PadOaep(data, span);
266 }
267 return TryEncryptOrDecrypt(key, span, destination, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_NO_PADDING_FLAG, null, encrypt, out bytesWritten);
268 }
269 finally
270 {
273 }
274 }
275 switch (padding.Mode)
276 {
277 case RSAEncryptionPaddingMode.Pkcs1:
278 return TryEncryptOrDecrypt(key, data, destination, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PKCS1_FLAG, null, encrypt, out bytesWritten);
279 case RSAEncryptionPaddingMode.Oaep:
280 {
282 try
283 {
284 global::Interop.BCrypt.BCRYPT_OAEP_PADDING_INFO bCRYPT_OAEP_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_OAEP_PADDING_INFO);
285 bCRYPT_OAEP_PADDING_INFO.pszAlgId = intPtr;
286 bCRYPT_OAEP_PADDING_INFO.pbLabel = IntPtr.Zero;
287 bCRYPT_OAEP_PADDING_INFO.cbLabel = 0;
288 global::Interop.BCrypt.BCRYPT_OAEP_PADDING_INFO bCRYPT_OAEP_PADDING_INFO2 = bCRYPT_OAEP_PADDING_INFO;
289 return TryEncryptOrDecrypt(key, data, destination, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_OAEP_FLAG, &bCRYPT_OAEP_PADDING_INFO2, encrypt, out bytesWritten);
290 }
291 finally
292 {
294 }
295 }
296 default:
298 }
299 }
300
301 private unsafe byte[] EncryptOrDecrypt(SafeNCryptKeyHandle key, ReadOnlySpan<byte> input, global::Interop.NCrypt.AsymmetricPaddingMode paddingMode, void* paddingInfo, bool encrypt)
302 {
303 int num = KeySize / 8;
304 byte[] array = new byte[num];
305 int bytesNeeded = 0;
306 global::Interop.NCrypt.ErrorCode errorCode = global::Interop.NCrypt.ErrorCode.ERROR_SUCCESS;
307 for (int i = 0; i <= 1; i++)
308 {
310 if (errorCode != global::Interop.NCrypt.ErrorCode.STATUS_UNSUCCESSFUL)
311 {
312 break;
313 }
314 }
315 if (errorCode == global::Interop.NCrypt.ErrorCode.NTE_BUFFER_TOO_SMALL)
316 {
318 array = new byte[bytesNeeded];
319 for (int j = 0; j <= 1; j++)
320 {
322 if (errorCode != global::Interop.NCrypt.ErrorCode.STATUS_UNSUCCESSFUL)
323 {
324 break;
325 }
326 }
327 }
328 if (errorCode != 0)
329 {
330 throw errorCode.ToCryptographicException();
331 }
332 if (bytesNeeded != array.Length)
333 {
334 byte[] array2 = array.AsSpan(0, bytesNeeded).ToArray();
336 array = array2;
337 }
338 return array;
339 }
340
341 private unsafe bool TryEncryptOrDecrypt(SafeNCryptKeyHandle key, ReadOnlySpan<byte> input, Span<byte> output, global::Interop.NCrypt.AsymmetricPaddingMode paddingMode, void* paddingInfo, bool encrypt, out int bytesWritten)
342 {
343 for (int i = 0; i <= 1; i++)
344 {
345 int bytesNeeded;
346 global::Interop.NCrypt.ErrorCode errorCode = EncryptOrDecrypt(key, input, output, paddingMode, paddingInfo, encrypt, out bytesNeeded);
347 switch (errorCode)
348 {
349 case global::Interop.NCrypt.ErrorCode.ERROR_SUCCESS:
351 return true;
352 case global::Interop.NCrypt.ErrorCode.NTE_BUFFER_TOO_SMALL:
353 bytesWritten = 0;
354 return false;
355 default:
356 throw errorCode.ToCryptographicException();
357 case global::Interop.NCrypt.ErrorCode.STATUS_UNSUCCESSFUL:
358 break;
359 }
360 }
361 throw global::Interop.NCrypt.ErrorCode.STATUS_UNSUCCESSFUL.ToCryptographicException();
362 }
363
364 private unsafe static global::Interop.NCrypt.ErrorCode EncryptOrDecrypt(SafeNCryptKeyHandle key, ReadOnlySpan<byte> input, Span<byte> output, global::Interop.NCrypt.AsymmetricPaddingMode paddingMode, void* paddingInfo, bool encrypt, out int bytesNeeded)
365 {
366 global::Interop.NCrypt.ErrorCode errorCode = (encrypt ? global::Interop.NCrypt.NCryptEncrypt(key, input, input.Length, paddingInfo, output, output.Length, out bytesNeeded, paddingMode) : global::Interop.NCrypt.NCryptDecrypt(key, input, input.Length, paddingInfo, output, output.Length, out bytesNeeded, paddingMode));
367 if (errorCode == global::Interop.NCrypt.ErrorCode.ERROR_SUCCESS && bytesNeeded > output.Length)
368 {
369 errorCode = global::Interop.NCrypt.ErrorCode.NTE_BUFFER_TOO_SMALL;
370 }
371 return errorCode;
372 }
373
374 public unsafe override void ImportParameters(RSAParameters parameters)
375 {
376 if (parameters.Exponent == null || parameters.Modulus == null)
377 {
379 }
380 bool flag;
381 if (parameters.D == null)
382 {
383 flag = false;
384 if (parameters.P != null || parameters.DP != null || parameters.Q != null || parameters.DQ != null || parameters.InverseQ != null)
385 {
387 }
388 }
389 else
390 {
391 flag = true;
392 if (parameters.P == null || parameters.DP == null || parameters.Q == null || parameters.DQ == null || parameters.InverseQ == null)
393 {
395 }
396 int num = (parameters.Modulus.Length + 1) / 2;
397 if (parameters.D.Length != parameters.Modulus.Length || parameters.P.Length != num || parameters.Q.Length != num || parameters.DP.Length != num || parameters.DQ.Length != num || parameters.InverseQ.Length != num)
398 {
400 }
401 }
402 int num2 = sizeof(global::Interop.BCrypt.BCRYPT_RSAKEY_BLOB) + parameters.Exponent.Length + parameters.Modulus.Length;
403 if (flag)
404 {
405 num2 += parameters.P.Length + parameters.Q.Length;
406 }
407 byte[] array = new byte[num2];
408 fixed (byte* ptr = &array[0])
409 {
410 global::Interop.BCrypt.BCRYPT_RSAKEY_BLOB* ptr2 = (global::Interop.BCrypt.BCRYPT_RSAKEY_BLOB*)ptr;
411 ptr2->Magic = (flag ? global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_RSAPRIVATE_MAGIC : global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_RSAPUBLIC_MAGIC);
412 ptr2->BitLength = parameters.Modulus.Length * 8;
413 ptr2->cbPublicExp = parameters.Exponent.Length;
414 ptr2->cbModulus = parameters.Modulus.Length;
415 if (flag)
416 {
417 ptr2->cbPrime1 = parameters.P.Length;
418 ptr2->cbPrime2 = parameters.Q.Length;
419 }
420 int offset = sizeof(global::Interop.BCrypt.BCRYPT_RSAKEY_BLOB);
421 global::Interop.BCrypt.Emit(array, ref offset, parameters.Exponent);
422 global::Interop.BCrypt.Emit(array, ref offset, parameters.Modulus);
423 if (flag)
424 {
425 global::Interop.BCrypt.Emit(array, ref offset, parameters.P);
426 global::Interop.BCrypt.Emit(array, ref offset, parameters.Q);
427 }
428 }
429 ImportKeyBlob(array, flag);
430 }
431
440
449
458
460 {
461 if (response.GetAlgorithmGroup() != "RSA")
462 {
463 response.FreeKey();
465 }
467 }
468
470 {
471 if (pbeParameters == null)
472 {
473 throw new ArgumentNullException("pbeParameters");
474 }
476 }
477
491
501
515
523
525 {
526 global::Interop.BCrypt.KeyBlobMagicNumber magic = (global::Interop.BCrypt.KeyBlobMagicNumber)BitConverter.ToInt32(rsaBlob, 0);
528 if (rsaBlob.Length < sizeof(global::Interop.BCrypt.BCRYPT_RSAKEY_BLOB))
529 {
530 throw global::Interop.NCrypt.ErrorCode.E_FAIL.ToCryptographicException();
531 }
532 fixed (byte* ptr = &rsaBlob[0])
533 {
534 global::Interop.BCrypt.BCRYPT_RSAKEY_BLOB* ptr2 = (global::Interop.BCrypt.BCRYPT_RSAKEY_BLOB*)ptr;
535 int offset = sizeof(global::Interop.BCrypt.BCRYPT_RSAKEY_BLOB);
536 rsaParams.Exponent = global::Interop.BCrypt.Consume(rsaBlob, ref offset, ptr2->cbPublicExp);
537 rsaParams.Modulus = global::Interop.BCrypt.Consume(rsaBlob, ref offset, ptr2->cbModulus);
539 {
540 rsaParams.P = global::Interop.BCrypt.Consume(rsaBlob, ref offset, ptr2->cbPrime1);
541 rsaParams.Q = global::Interop.BCrypt.Consume(rsaBlob, ref offset, ptr2->cbPrime2);
542 rsaParams.DP = global::Interop.BCrypt.Consume(rsaBlob, ref offset, ptr2->cbPrime1);
543 rsaParams.DQ = global::Interop.BCrypt.Consume(rsaBlob, ref offset, ptr2->cbPrime2);
544 rsaParams.InverseQ = global::Interop.BCrypt.Consume(rsaBlob, ref offset, ptr2->cbPrime1);
545 rsaParams.D = global::Interop.BCrypt.Consume(rsaBlob, ref offset, ptr2->cbModulus);
546 }
547 }
548 }
549
550 private static void CheckMagicValueOfKey(global::Interop.BCrypt.KeyBlobMagicNumber magic, bool includePrivateParameters)
551 {
553 {
554 if (magic != global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_RSAPRIVATE_MAGIC && magic != global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_RSAFULLPRIVATE_MAGIC)
555 {
557 }
558 }
559 else if (magic != global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_RSAPUBLIC_MAGIC && magic != global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_RSAPRIVATE_MAGIC && magic != global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_RSAFULLPRIVATE_MAGIC)
560 {
562 }
563 }
564
565 private static int GetHashSizeInBytes(HashAlgorithmName hashAlgorithm)
566 {
567 return s_hashSizes.GetOrAdd(hashAlgorithm, delegate(HashAlgorithmName hashAlgorithm)
568 {
569 using HashProviderCng hashProviderCng = new HashProviderCng(hashAlgorithm.Name, null);
570 return hashProviderCng.HashSizeInBytes;
571 });
572 }
573
574 public unsafe override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
575 {
576 if (hash == null)
577 {
578 throw new ArgumentNullException("hash");
579 }
580 string name = hashAlgorithm.Name;
581 if (string.IsNullOrEmpty(name))
582 {
584 }
585 if (padding == null)
586 {
587 throw new ArgumentNullException("padding");
588 }
589 if (hash.Length != GetHashSizeInBytes(hashAlgorithm))
590 {
592 }
595 try
596 {
597 int estimatedSize = KeySize / 8;
598 switch (padding.Mode)
599 {
600 case RSASignaturePaddingMode.Pkcs1:
601 {
602 global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO bCRYPT_PKCS1_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO);
603 bCRYPT_PKCS1_PADDING_INFO.pszAlgId = intPtr;
604 global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO bCRYPT_PKCS1_PADDING_INFO2 = bCRYPT_PKCS1_PADDING_INFO;
605 return keyHandle.SignHash(hash, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PKCS1_FLAG, &bCRYPT_PKCS1_PADDING_INFO2, estimatedSize);
606 }
608 {
609 global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO bCRYPT_PSS_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO);
610 bCRYPT_PSS_PADDING_INFO.pszAlgId = intPtr;
611 bCRYPT_PSS_PADDING_INFO.cbSalt = hash.Length;
612 global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO bCRYPT_PSS_PADDING_INFO2 = bCRYPT_PSS_PADDING_INFO;
613 return keyHandle.SignHash(hash, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PSS_FLAG, &bCRYPT_PSS_PADDING_INFO2, estimatedSize);
614 }
615 default:
617 }
618 }
619 finally
620 {
622 }
623 }
624
626 {
627 string name = hashAlgorithm.Name;
628 if (string.IsNullOrEmpty(name))
629 {
631 }
632 if (padding == null)
633 {
634 throw new ArgumentNullException("padding");
635 }
637 if (hash.Length != GetHashSizeInBytes(hashAlgorithm))
638 {
640 }
642 try
643 {
644 switch (padding.Mode)
645 {
646 case RSASignaturePaddingMode.Pkcs1:
647 {
648 global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO bCRYPT_PKCS1_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO);
649 bCRYPT_PKCS1_PADDING_INFO.pszAlgId = intPtr;
650 global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO bCRYPT_PKCS1_PADDING_INFO2 = bCRYPT_PKCS1_PADDING_INFO;
651 return keyHandle.TrySignHash(hash, destination, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PKCS1_FLAG, &bCRYPT_PKCS1_PADDING_INFO2, out bytesWritten);
652 }
654 {
655 global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO bCRYPT_PSS_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO);
656 bCRYPT_PSS_PADDING_INFO.pszAlgId = intPtr;
657 bCRYPT_PSS_PADDING_INFO.cbSalt = hash.Length;
658 global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO bCRYPT_PSS_PADDING_INFO2 = bCRYPT_PSS_PADDING_INFO;
659 return keyHandle.TrySignHash(hash, destination, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PSS_FLAG, &bCRYPT_PSS_PADDING_INFO2, out bytesWritten);
660 }
661 default:
663 }
664 }
665 finally
666 {
668 }
669 }
670
671 public override bool VerifyHash(byte[] hash, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
672 {
673 if (hash == null)
674 {
675 throw new ArgumentNullException("hash");
676 }
677 if (signature == null)
678 {
679 throw new ArgumentNullException("signature");
680 }
681 return VerifyHash((ReadOnlySpan<byte>)hash, (ReadOnlySpan<byte>)signature, hashAlgorithm, padding);
682 }
683
685 {
686 string name = hashAlgorithm.Name;
687 if (string.IsNullOrEmpty(name))
688 {
690 }
691 if (padding == null)
692 {
693 throw new ArgumentNullException("padding");
694 }
696 if (hash.Length != GetHashSizeInBytes(hashAlgorithm))
697 {
698 return false;
699 }
701 try
702 {
703 switch (padding.Mode)
704 {
705 case RSASignaturePaddingMode.Pkcs1:
706 {
707 global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO bCRYPT_PKCS1_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO);
708 bCRYPT_PKCS1_PADDING_INFO.pszAlgId = intPtr;
709 global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO bCRYPT_PKCS1_PADDING_INFO2 = bCRYPT_PKCS1_PADDING_INFO;
710 return keyHandle.VerifyHash(hash, signature, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PKCS1_FLAG, &bCRYPT_PKCS1_PADDING_INFO2);
711 }
713 {
714 global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO bCRYPT_PSS_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO);
715 bCRYPT_PSS_PADDING_INFO.pszAlgId = intPtr;
716 bCRYPT_PSS_PADDING_INFO.cbSalt = hash.Length;
717 global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO bCRYPT_PSS_PADDING_INFO2 = bCRYPT_PSS_PADDING_INFO;
718 return keyHandle.VerifyHash(hash, signature, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PSS_FLAG, &bCRYPT_PSS_PADDING_INFO2);
719 }
720 default:
722 }
723 }
724 finally
725 {
727 }
728 }
729 }
730}
static byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
Definition CngCommon.cs:10
static bool TryHashData(ReadOnlySpan< byte > source, Span< byte > destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
Definition CngCommon.cs:17
static int ToInt32(byte[] value, int startIndex)
static void FreeHGlobal(IntPtr hglobal)
Definition Marshal.cs:1680
static unsafe IntPtr StringToHGlobalUni(string? s)
Definition Marshal.cs:1310
static string Cryptography_NotValidPrivateKey
Definition SR.cs:120
static string Cryptography_RSA_DecryptWrongSize
Definition SR.cs:138
static string Cryptography_InvalidRsaParameters
Definition SR.cs:108
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Cryptography_NotValidPublicOrPrivateKey
Definition SR.cs:122
static string Cryptography_UnsupportedPaddingMode
Definition SR.cs:160
static string Cryptography_SignHash_WrongSize
Definition SR.cs:142
static string Cryptography_Encryption_MessageTooLong
Definition SR.cs:52
static string Cryptography_HashAlgorithmNameNullOrEmpty
Definition SR.cs:60
Definition SR.cs:7
static bool TryExportPkcs8KeyBlob(SafeNCryptKeyHandle keyHandle, ReadOnlySpan< char > password, int kdfCount, Span< byte > destination, out int bytesWritten)
Definition CngKeyLite.cs:93
static byte[] ExportPkcs8KeyBlob(SafeNCryptKeyHandle keyHandle, ReadOnlySpan< char > password, int kdfCount)
Definition CngKeyLite.cs:85
static unsafe SafeNCryptKeyHandle ImportKeyBlob(string blobType, ReadOnlySpan< byte > keyBlob, bool encrypted=false, ReadOnlySpan< char > password=default(ReadOnlySpan< char >))
Definition CngKeyLite.cs:14
static byte[] ExportKeyBlob(SafeNCryptKeyHandle keyHandle, string blobType)
Definition CngKeyLite.cs:58
static int GetKeyLength(SafeNCryptKeyHandle keyHandle)
static SafeNCryptKeyHandle GenerateNewExportableKey(string algorithm, int keySize)
static bool IsPlatformScheme(PbeParameters pbeParameters)
Definition CngPkcs8.cs:44
static unsafe Pkcs8Response ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > source, out int bytesRead)
Definition CngPkcs8.cs:134
static byte[] ExportEncryptedPkcs8PrivateKey(AsymmetricAlgorithm key, ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters)
Definition CngPkcs8.cs:53
static Pkcs8Response ImportPkcs8PrivateKey(ReadOnlySpan< byte > source, out int bytesRead)
Definition CngPkcs8.cs:90
static bool TryExportEncryptedPkcs8PrivateKey(AsymmetricAlgorithm key, ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
Definition CngPkcs8.cs:68
static void Return(byte[] array, int clearSize=-1)
Definition CryptoPool.cs:12
static byte[] Rent(int minimumLength)
Definition CryptoPool.cs:7
static void ValidatePbeParameters(PbeParameters pbeParameters, ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes)
byte[] ExportKeyBlob(bool includePrivateParameters)
override bool TryDecrypt(ReadOnlySpan< byte > data, Span< byte > destination, RSAEncryptionPadding padding, out int bytesWritten)
override bool TryHashData(ReadOnlySpan< byte > data, Span< byte > destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
bool TryExportEncryptedPkcs8(ReadOnlySpan< char > pkcs8Password, int kdfCount, Span< byte > destination, out int bytesWritten)
void AcceptImport(CngPkcs8.Pkcs8Response response)
void ProcessPkcs8Response(CngPkcs8.Pkcs8Response response)
unsafe override bool TrySignHash(ReadOnlySpan< byte > hash, Span< byte > destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
unsafe bool TryEncryptOrDecrypt(SafeNCryptKeyHandle key, ReadOnlySpan< byte > input, Span< byte > output, global::Interop.NCrypt.AsymmetricPaddingMode paddingMode, void *paddingInfo, bool encrypt, out int bytesWritten)
override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, ReadOnlySpan< byte > source, out int bytesRead)
unsafe byte[] EncryptOrDecrypt(byte[] data, RSAEncryptionPadding padding, bool encrypt)
override bool VerifyHash(byte[] hash, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
override void ImportPkcs8PrivateKey(ReadOnlySpan< byte > source, out int bytesRead)
override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
static int GetHashSizeInBytes(HashAlgorithmName hashAlgorithm)
byte[] ExportEncryptedPkcs8(ReadOnlySpan< char > pkcs8Password, int kdfCount)
override bool TryEncrypt(ReadOnlySpan< byte > data, Span< byte > destination, RSAEncryptionPadding padding, out int bytesWritten)
static unsafe void ExportParameters(ref RSAParameters rsaParams, byte[] rsaBlob, bool includePrivateParameters)
static void CheckMagicValueOfKey(global::Interop.BCrypt.KeyBlobMagicNumber magic, bool includePrivateParameters)
override byte[] Decrypt(byte[] data, RSAEncryptionPadding padding)
static unsafe global::Interop.NCrypt.ErrorCode EncryptOrDecrypt(SafeNCryptKeyHandle key, ReadOnlySpan< byte > input, Span< byte > output, global::Interop.NCrypt.AsymmetricPaddingMode paddingMode, void *paddingInfo, bool encrypt, out int bytesNeeded)
unsafe override bool VerifyHash(ReadOnlySpan< byte > hash, ReadOnlySpan< byte > signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
override byte[] ExportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters)
unsafe override void ImportParameters(RSAParameters parameters)
override byte[] Encrypt(byte[] data, RSAEncryptionPadding padding)
unsafe bool TryEncryptOrDecrypt(ReadOnlySpan< byte > data, Span< byte > destination, RSAEncryptionPadding padding, bool encrypt, out int bytesWritten)
void ImportKeyBlob(byte[] rsaBlob, bool includePrivate)
override byte[] ExportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, PbeParameters pbeParameters)
override RSAParameters ExportParameters(bool includePrivateParameters)
override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > source, out int bytesRead)
override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
static readonly ConcurrentDictionary< HashAlgorithmName, int > s_hashSizes
unsafe override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
unsafe byte[] EncryptOrDecrypt(SafeNCryptKeyHandle key, ReadOnlySpan< byte > input, global::Interop.NCrypt.AsymmetricPaddingMode paddingMode, void *paddingInfo, bool encrypt)
static void PadPkcs1Encryption(ReadOnlySpan< byte > source, Span< byte > destination)
static RsaPaddingProcessor OpenProcessor(HashAlgorithmName hashAlgorithmName)
static readonly IntPtr Zero
Definition IntPtr.cs:18