mscorlib(4.0.0.0) API with additions
RSACryptoServiceProvider.cs
1 using System.IO;
6 
8 {
10  [ComVisible(true)]
12  {
13  private int _dwKeySize;
14 
15  private CspParameters _parameters;
16 
17  private bool _randomKeyContainer;
18 
19  [SecurityCritical]
20  private SafeProvHandle _safeProvHandle;
21 
22  [SecurityCritical]
23  private SafeKeyHandle _safeKeyHandle;
24 
25  private static volatile CspProviderFlags s_UseMachineKeyStore;
26 
30  [ComVisible(false)]
31  public bool PublicOnly
32  {
33  [SecuritySafeCritical]
34  get
35  {
36  GetKeyPair();
37  byte[] array = Utils._GetKeyParameter(_safeKeyHandle, 2u);
38  return array[0] == 1;
39  }
40  }
41 
44  [ComVisible(false)]
46  {
47  [SecuritySafeCritical]
48  get
49  {
50  GetKeyPair();
51  return new CspKeyContainerInfo(_parameters, _randomKeyContainer);
52  }
53  }
54 
57  public override int KeySize
58  {
59  [SecuritySafeCritical]
60  get
61  {
62  GetKeyPair();
63  byte[] array = Utils._GetKeyParameter(_safeKeyHandle, 1u);
64  _dwKeySize = (array[0] | (array[1] << 8) | (array[2] << 16) | (array[3] << 24));
65  return _dwKeySize;
66  }
67  }
68 
71  public override string KeyExchangeAlgorithm
72  {
73  get
74  {
75  if (_parameters.KeyNumber == 1)
76  {
77  return "RSA-PKCS1-KeyEx";
78  }
79  return null;
80  }
81  }
82 
85  public override string SignatureAlgorithm => "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
86 
90  public static bool UseMachineKeyStore
91  {
92  get
93  {
94  return s_UseMachineKeyStore == CspProviderFlags.UseMachineKeyStore;
95  }
96  set
97  {
98  s_UseMachineKeyStore = (value ? CspProviderFlags.UseMachineKeyStore : CspProviderFlags.NoFlags);
99  }
100  }
101 
105  public bool PersistKeyInCsp
106  {
107  [SecuritySafeCritical]
108  get
109  {
110  if (_safeProvHandle == null)
111  {
112  lock (this)
113  {
114  if (_safeProvHandle == null)
115  {
116  _safeProvHandle = Utils.CreateProvHandle(_parameters, _randomKeyContainer);
117  }
118  }
119  }
120  return Utils.GetPersistKeyInCsp(_safeProvHandle);
121  }
122  [SecuritySafeCritical]
123  set
124  {
125  bool persistKeyInCsp = PersistKeyInCsp;
126  if (value == persistKeyInCsp)
127  {
128  return;
129  }
130  if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
131  {
132  KeyContainerPermission keyContainerPermission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
133  if (!value)
134  {
136  keyContainerPermission.AccessEntries.Add(accessEntry);
137  }
138  else
139  {
141  keyContainerPermission.AccessEntries.Add(accessEntry2);
142  }
143  keyContainerPermission.Demand();
144  }
145  Utils.SetPersistKeyInCsp(_safeProvHandle, value);
146  }
147  }
148 
149  [DllImport("QCall", CharSet = CharSet.Unicode)]
150  [SecurityCritical]
151  [SuppressUnmanagedCodeSecurity]
152  private static extern void DecryptKey(SafeKeyHandle pKeyContext, [MarshalAs(UnmanagedType.LPArray)] byte[] pbEncryptedKey, int cbEncryptedKey, [MarshalAs(UnmanagedType.Bool)] bool fOAEP, ObjectHandleOnStack ohRetDecryptedKey);
153 
154  [DllImport("QCall", CharSet = CharSet.Unicode)]
155  [SecurityCritical]
156  [SuppressUnmanagedCodeSecurity]
157  private static extern void EncryptKey(SafeKeyHandle pKeyContext, [MarshalAs(UnmanagedType.LPArray)] byte[] pbKey, int cbKey, [MarshalAs(UnmanagedType.Bool)] bool fOAEP, ObjectHandleOnStack ohRetEncryptedKey);
158 
161  [SecuritySafeCritical]
163  : this(0, new CspParameters(24, null, null, s_UseMachineKeyStore), useDefaultKeySize: true)
164  {
165  }
166 
170  [SecuritySafeCritical]
171  public RSACryptoServiceProvider(int dwKeySize)
172  : this(dwKeySize, new CspParameters(24, null, null, s_UseMachineKeyStore), useDefaultKeySize: false)
173  {
174  }
175 
179  [SecuritySafeCritical]
181  : this(0, parameters, useDefaultKeySize: true)
182  {
183  }
184 
189  [SecuritySafeCritical]
190  public RSACryptoServiceProvider(int dwKeySize, CspParameters parameters)
191  : this(dwKeySize, parameters, useDefaultKeySize: false)
192  {
193  }
194 
195  [SecurityCritical]
196  private RSACryptoServiceProvider(int dwKeySize, CspParameters parameters, bool useDefaultKeySize)
197  {
198  if (dwKeySize < 0)
199  {
200  throw new ArgumentOutOfRangeException("dwKeySize", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
201  }
202  _parameters = Utils.SaveCspParameters(CspAlgorithmType.Rsa, parameters, s_UseMachineKeyStore, ref _randomKeyContainer);
203  LegalKeySizesValue = new KeySizes[1]
204  {
205  new KeySizes(384, 16384, 8)
206  };
207  _dwKeySize = (useDefaultKeySize ? 1024 : dwKeySize);
208  if (!_randomKeyContainer || Environment.GetCompatibilityFlag(CompatibilityFlag.EagerlyGenerateRandomAsymmKeys))
209  {
210  GetKeyPair();
211  }
212  }
213 
214  [SecurityCritical]
215  private void GetKeyPair()
216  {
217  if (_safeKeyHandle == null)
218  {
219  lock (this)
220  {
221  if (_safeKeyHandle == null)
222  {
223  Utils.GetKeyPairHelper(CspAlgorithmType.Rsa, _parameters, _randomKeyContainer, _dwKeySize, ref _safeProvHandle, ref _safeKeyHandle);
224  }
225  }
226  }
227  }
228 
229  [SecuritySafeCritical]
230  protected override void Dispose(bool disposing)
231  {
232  base.Dispose(disposing);
233  if (_safeKeyHandle != null && !_safeKeyHandle.IsClosed)
234  {
235  _safeKeyHandle.Dispose();
236  }
237  if (_safeProvHandle != null && !_safeProvHandle.IsClosed)
238  {
239  _safeProvHandle.Dispose();
240  }
241  }
242 
248  [SecuritySafeCritical]
249  public override RSAParameters ExportParameters(bool includePrivateParameters)
250  {
251  GetKeyPair();
252  if (includePrivateParameters && !CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
253  {
254  KeyContainerPermission keyContainerPermission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
256  keyContainerPermission.AccessEntries.Add(accessEntry);
257  keyContainerPermission.Demand();
258  }
259  RSACspObject rSACspObject = new RSACspObject();
260  int blobType = includePrivateParameters ? 7 : 6;
261  Utils._ExportKey(_safeKeyHandle, blobType, rSACspObject);
262  return RSAObjectToStruct(rSACspObject);
263  }
264 
269  [SecuritySafeCritical]
270  [ComVisible(false)]
271  public byte[] ExportCspBlob(bool includePrivateParameters)
272  {
273  GetKeyPair();
274  return Utils.ExportCspBlobHelper(includePrivateParameters, _parameters, _safeKeyHandle);
275  }
276 
280  [SecuritySafeCritical]
281  public override void ImportParameters(RSAParameters parameters)
282  {
283  if (_safeKeyHandle != null && !_safeKeyHandle.IsClosed)
284  {
285  _safeKeyHandle.Dispose();
286  _safeKeyHandle = null;
287  }
288  RSACspObject cspObject = RSAStructToObject(parameters);
289  _safeKeyHandle = SafeKeyHandle.InvalidHandle;
290  if (IsPublic(parameters))
291  {
292  Utils._ImportKey(Utils.StaticProvHandle, 41984, CspProviderFlags.NoFlags, cspObject, ref _safeKeyHandle);
293  return;
294  }
295  if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
296  {
297  KeyContainerPermission keyContainerPermission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
299  keyContainerPermission.AccessEntries.Add(accessEntry);
300  keyContainerPermission.Demand();
301  }
302  if (_safeProvHandle == null)
303  {
304  _safeProvHandle = Utils.CreateProvHandle(_parameters, _randomKeyContainer);
305  }
306  Utils._ImportKey(_safeProvHandle, 41984, _parameters.Flags, cspObject, ref _safeKeyHandle);
307  }
308 
311  [SecuritySafeCritical]
312  [ComVisible(false)]
313  public void ImportCspBlob(byte[] keyBlob)
314  {
315  Utils.ImportCspBlobHelper(CspAlgorithmType.Rsa, keyBlob, IsPublic(keyBlob), ref _parameters, _randomKeyContainer, ref _safeProvHandle, ref _safeKeyHandle);
316  }
317 
324  public byte[] SignData(Stream inputStream, object halg)
325  {
326  int calgHash = Utils.ObjToAlgId(halg, OidGroup.HashAlgorithm);
327  HashAlgorithm hashAlgorithm = Utils.ObjToHashAlgorithm(halg);
328  byte[] rgbHash = hashAlgorithm.ComputeHash(inputStream);
329  return SignHash(rgbHash, calgHash);
330  }
331 
338  public byte[] SignData(byte[] buffer, object halg)
339  {
340  int calgHash = Utils.ObjToAlgId(halg, OidGroup.HashAlgorithm);
341  HashAlgorithm hashAlgorithm = Utils.ObjToHashAlgorithm(halg);
342  byte[] rgbHash = hashAlgorithm.ComputeHash(buffer);
343  return SignHash(rgbHash, calgHash);
344  }
345 
354  public byte[] SignData(byte[] buffer, int offset, int count, object halg)
355  {
356  int calgHash = Utils.ObjToAlgId(halg, OidGroup.HashAlgorithm);
357  HashAlgorithm hashAlgorithm = Utils.ObjToHashAlgorithm(halg);
358  byte[] rgbHash = hashAlgorithm.ComputeHash(buffer, offset, count);
359  return SignHash(rgbHash, calgHash);
360  }
361 
370  public bool VerifyData(byte[] buffer, object halg, byte[] signature)
371  {
372  int calgHash = Utils.ObjToAlgId(halg, OidGroup.HashAlgorithm);
373  HashAlgorithm hashAlgorithm = Utils.ObjToHashAlgorithm(halg);
374  byte[] rgbHash = hashAlgorithm.ComputeHash(buffer);
375  return VerifyHash(rgbHash, calgHash, signature);
376  }
377 
384  public byte[] SignHash(byte[] rgbHash, string str)
385  {
386  if (rgbHash == null)
387  {
388  throw new ArgumentNullException("rgbHash");
389  }
390  if (PublicOnly)
391  {
392  throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_NoPrivateKey"));
393  }
394  int calgHash = X509Utils.NameOrOidToAlgId(str, OidGroup.HashAlgorithm);
395  return SignHash(rgbHash, calgHash);
396  }
397 
398  [SecuritySafeCritical]
399  internal byte[] SignHash(byte[] rgbHash, int calgHash)
400  {
401  GetKeyPair();
402  if (!CspKeyContainerInfo.RandomlyGenerated && !CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
403  {
404  KeyContainerPermission keyContainerPermission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
406  keyContainerPermission.AccessEntries.Add(accessEntry);
407  keyContainerPermission.Demand();
408  }
409  return Utils.SignValue(_safeKeyHandle, _parameters.KeyNumber, 9216, calgHash, rgbHash);
410  }
411 
420  public bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature)
421  {
422  if (rgbHash == null)
423  {
424  throw new ArgumentNullException("rgbHash");
425  }
426  if (rgbSignature == null)
427  {
428  throw new ArgumentNullException("rgbSignature");
429  }
430  int calgHash = X509Utils.NameOrOidToAlgId(str, OidGroup.HashAlgorithm);
431  return VerifyHash(rgbHash, calgHash, rgbSignature);
432  }
433 
434  [SecuritySafeCritical]
435  internal bool VerifyHash(byte[] rgbHash, int calgHash, byte[] rgbSignature)
436  {
437  GetKeyPair();
438  return Utils.VerifySign(_safeKeyHandle, 9216, calgHash, rgbHash, rgbSignature);
439  }
440 
449  [SecuritySafeCritical]
450  public byte[] Encrypt(byte[] rgb, bool fOAEP)
451  {
452  if (rgb == null)
453  {
454  throw new ArgumentNullException("rgb");
455  }
456  GetKeyPair();
457  byte[] o = null;
458  EncryptKey(_safeKeyHandle, rgb, rgb.Length, fOAEP, JitHelpers.GetObjectHandleOnStack(ref o));
459  return o;
460  }
461 
470  [SecuritySafeCritical]
471  public byte[] Decrypt(byte[] rgb, bool fOAEP)
472  {
473  if (rgb == null)
474  {
475  throw new ArgumentNullException("rgb");
476  }
477  GetKeyPair();
478  if (rgb.Length > KeySize / 8)
479  {
480  throw new CryptographicException(Environment.GetResourceString("Cryptography_Padding_DecDataTooBig", KeySize / 8));
481  }
482  if (!CspKeyContainerInfo.RandomlyGenerated && !CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
483  {
484  KeyContainerPermission keyContainerPermission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
486  keyContainerPermission.AccessEntries.Add(accessEntry);
487  keyContainerPermission.Demand();
488  }
489  byte[] o = null;
490  DecryptKey(_safeKeyHandle, rgb, rgb.Length, fOAEP, JitHelpers.GetObjectHandleOnStack(ref o));
491  return o;
492  }
493 
498  public override byte[] DecryptValue(byte[] rgb)
499  {
500  throw new NotSupportedException(Environment.GetResourceString("NotSupported_Method"));
501  }
502 
507  public override byte[] EncryptValue(byte[] rgb)
508  {
509  throw new NotSupportedException(Environment.GetResourceString("NotSupported_Method"));
510  }
511 
512  private static RSAParameters RSAObjectToStruct(RSACspObject rsaCspObject)
513  {
514  RSAParameters result = default(RSAParameters);
515  result.Exponent = rsaCspObject.Exponent;
516  result.Modulus = rsaCspObject.Modulus;
517  result.P = rsaCspObject.P;
518  result.Q = rsaCspObject.Q;
519  result.DP = rsaCspObject.DP;
520  result.DQ = rsaCspObject.DQ;
521  result.InverseQ = rsaCspObject.InverseQ;
522  result.D = rsaCspObject.D;
523  return result;
524  }
525 
526  private static RSACspObject RSAStructToObject(RSAParameters rsaParams)
527  {
528  RSACspObject rSACspObject = new RSACspObject();
529  rSACspObject.Exponent = rsaParams.Exponent;
530  rSACspObject.Modulus = rsaParams.Modulus;
531  rSACspObject.P = rsaParams.P;
532  rSACspObject.Q = rsaParams.Q;
533  rSACspObject.DP = rsaParams.DP;
534  rSACspObject.DQ = rsaParams.DQ;
535  rSACspObject.InverseQ = rsaParams.InverseQ;
536  rSACspObject.D = rsaParams.D;
537  return rSACspObject;
538  }
539 
540  private static bool IsPublic(byte[] keyBlob)
541  {
542  if (keyBlob == null)
543  {
544  throw new ArgumentNullException("keyBlob");
545  }
546  if (keyBlob[0] != 6)
547  {
548  return false;
549  }
550  if (keyBlob[11] != 49 || keyBlob[10] != 65 || keyBlob[9] != 83 || keyBlob[8] != 82)
551  {
552  return false;
553  }
554  return true;
555  }
556 
557  private static bool IsPublic(RSAParameters rsaParams)
558  {
559  return rsaParams.P == null;
560  }
561 
562  [SecuritySafeCritical]
563  protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
564  {
565  using (SafeHashHandle hHash = Utils.CreateHash(Utils.StaticProvHandle, GetAlgorithmId(hashAlgorithm)))
566  {
567  Utils.HashData(hHash, data, offset, count);
568  return Utils.EndHash(hHash);
569  }
570  }
571 
572  [SecuritySafeCritical]
573  protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
574  {
575  using (SafeHashHandle hHash = Utils.CreateHash(Utils.StaticProvHandle, GetAlgorithmId(hashAlgorithm)))
576  {
577  byte[] array = new byte[4096];
578  int num = 0;
579  do
580  {
581  num = data.Read(array, 0, array.Length);
582  if (num > 0)
583  {
584  Utils.HashData(hHash, array, 0, num);
585  }
586  }
587  while (num > 0);
588  return Utils.EndHash(hHash);
589  }
590  }
591 
592  private static int GetAlgorithmId(HashAlgorithmName hashAlgorithm)
593  {
594  switch (hashAlgorithm.Name)
595  {
596  case "MD5":
597  return 32771;
598  case "SHA1":
599  return 32772;
600  case "SHA256":
601  return 32780;
602  case "SHA384":
603  return 32781;
604  case "SHA512":
605  return 32782;
606  default:
607  throw new CryptographicException(Environment.GetResourceString("Cryptography_UnknownHashAlgorithm", hashAlgorithm.Name));
608  }
609  }
610 
619  public override byte[] Encrypt(byte[] data, RSAEncryptionPadding padding)
620  {
621  if (data == null)
622  {
623  throw new ArgumentNullException("data");
624  }
625  if (padding == null)
626  {
627  throw new ArgumentNullException("padding");
628  }
629  if (padding == RSAEncryptionPadding.Pkcs1)
630  {
631  return Encrypt(data, fOAEP: false);
632  }
633  if (padding == RSAEncryptionPadding.OaepSHA1)
634  {
635  return Encrypt(data, fOAEP: true);
636  }
637  throw PaddingModeNotSupported();
638  }
639 
648  public override byte[] Decrypt(byte[] data, RSAEncryptionPadding padding)
649  {
650  if (data == null)
651  {
652  throw new ArgumentNullException("data");
653  }
654  if (padding == null)
655  {
656  throw new ArgumentNullException("padding");
657  }
658  if (padding == RSAEncryptionPadding.Pkcs1)
659  {
660  return Decrypt(data, fOAEP: false);
661  }
662  if (padding == RSAEncryptionPadding.OaepSHA1)
663  {
664  return Decrypt(data, fOAEP: true);
665  }
666  throw PaddingModeNotSupported();
667  }
668 
681  public override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
682  {
683  if (hash == null)
684  {
685  throw new ArgumentNullException("hash");
686  }
687  if (string.IsNullOrEmpty(hashAlgorithm.Name))
688  {
689  throw RSA.HashAlgorithmNameNullOrEmpty();
690  }
691  if (padding == null)
692  {
693  throw new ArgumentNullException("padding");
694  }
695  if (padding != RSASignaturePadding.Pkcs1)
696  {
697  throw PaddingModeNotSupported();
698  }
699  return SignHash(hash, GetAlgorithmId(hashAlgorithm));
700  }
701 
716  public override bool VerifyHash(byte[] hash, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
717  {
718  if (hash == null)
719  {
720  throw new ArgumentNullException("hash");
721  }
722  if (signature == null)
723  {
724  throw new ArgumentNullException("signature");
725  }
726  if (string.IsNullOrEmpty(hashAlgorithm.Name))
727  {
728  throw RSA.HashAlgorithmNameNullOrEmpty();
729  }
730  if (padding == null)
731  {
732  throw new ArgumentNullException("padding");
733  }
734  if (padding != RSASignaturePadding.Pkcs1)
735  {
736  throw PaddingModeNotSupported();
737  }
738  return VerifyHash(hash, GetAlgorithmId(hashAlgorithm), signature);
739  }
740 
741  private static Exception PaddingModeNotSupported()
742  {
743  return new CryptographicException(Environment.GetResourceString("Cryptography_InvalidPaddingMode"));
744  }
745  }
746 }
The exception that is thrown when an error occurs during a cryptographic operation.
override int KeySize
Gets the size of the current key.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Performs asymmetric encryption and decryption using the implementation of the T:System....
static bool? UseMachineKeyStore
Gets or sets a value indicating whether the key should be persisted in the computer's key store inste...
byte [] Modulus
Represents the Modulus parameter for the T:System.Security.Cryptography.RSA algorithm.
override byte [] HashData(Stream data, HashAlgorithmName hashAlgorithm)
When overridden in a derived class, computes the hash value of a specified binary stream by using a s...
void ImportCspBlob(byte[] keyBlob)
Imports a blob that represents RSA key information.
int KeyNumber
Specifies whether an asymmetric key is created as a signature key or an exchange key.
string Name
Gets the underlying string representation of the algorithm name.
byte [] Encrypt(byte[] rgb, bool fOAEP)
Encrypts data with the T:System.Security.Cryptography.RSA algorithm.
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
Specifies access rights for specific key containers. This class cannot be inherited.
CspProviderFlags
Specifies flags that modify the behavior of the cryptographic service providers (CSP).
byte [] D
Represents the D parameter for the T:System.Security.Cryptography.RSA algorithm.
bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature)
Verifies that a digital signature is valid by determining the hash value in the signature using the p...
OidGroup
Identifies Windows cryptographic object identifier (OID) groups.
Definition: OidGroup.cs:4
Controls the ability to access key containers. This class cannot be inherited.
override byte [] EncryptValue(byte[] rgb)
This method is not supported in the current version.
override void Dispose(bool disposing)
Releases the unmanaged resources used by the T:System.Security.Cryptography.AsymmetricAlgorithm class...
Defines methods that allow an T:System.Security.Cryptography.AsymmetricAlgorithm class to enumerate k...
RSACryptoServiceProvider(CspParameters parameters)
Initializes a new instance of the T:System.Security.Cryptography.RSACryptoServiceProvider class with ...
Specifies the name of a cryptographic hash algorithm.
bool PublicOnly
Gets a value that indicates whether the T:System.Security.Cryptography.RSACryptoServiceProvider objec...
bool PersistKeyInCsp
Gets or sets a value indicating whether the key should be persisted in the cryptographic service prov...
Specifies the padding mode and parameters to use with RSA encryption or decryption operations.
KeySizes [] LegalKeySizesValue
Specifies the key sizes that are supported by the asymmetric algorithm.
byte [] SignData(byte[] buffer, int offset, int count, object halg)
Computes the hash value of a subset of the specified byte array using the specified hash algorithm,...
override string SignatureAlgorithm
Gets the name of the signature algorithm available with this implementation of T:System....
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
override byte [] Encrypt(byte[] data, RSAEncryptionPadding padding)
Encrypts data with the T:System.Security.Cryptography.RSA algorithm using the specified padding.
byte [] ExportCspBlob(bool includePrivateParameters)
Exports a blob containing the key information associated with an T:System.Security....
Represents the standard parameters for the T:System.Security.Cryptography.RSA algorithm.
Definition: RSAParameters.cs:8
static RSAEncryptionPadding OaepSHA1
Gets an object that represents the Optimal Asymmetric Encryption Padding (OAEP) encryption standard w...
RSACryptoServiceProvider(int dwKeySize, CspParameters parameters)
Initializes a new instance of the T:System.Security.Cryptography.RSACryptoServiceProvider class with ...
RSACryptoServiceProvider(int dwKeySize)
Initializes a new instance of the T:System.Security.Cryptography.RSACryptoServiceProvider class with ...
RSACryptoServiceProvider()
Initializes a new instance of the T:System.Security.Cryptography.RSACryptoServiceProvider class using...
override byte [] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Computes the signature for the specified hash value by encrypting it with the private key using the s...
UnmanagedType
Identifies how to marshal parameters or fields to unmanaged code.
Definition: UnmanagedType.cs:7
byte [] DQ
Represents the DQ parameter for the T:System.Security.Cryptography.RSA algorithm.
byte [] SignHash(byte[] rgbHash, string str)
Computes the signature for the specified hash value by encrypting it with the private key.
int Add(KeyContainerPermissionAccessEntry accessEntry)
Adds a T:System.Security.Permissions.KeyContainerPermissionAccessEntry object to the collection.
KeyContainerPermissionAccessEntryCollection AccessEntries
Gets the collection of T:System.Security.Permissions.KeyContainerPermissionAccessEntry objects associ...
byte [] P
Represents the P parameter for the T:System.Security.Cryptography.RSA algorithm.
byte [] InverseQ
Represents the InverseQ parameter for the T:System.Security.Cryptography.RSA algorithm.
override byte [] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
When overridden in a derived class, computes the hash value of a specified portion of a byte array by...
override bool VerifyHash(byte[] hash, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Verifies that a digital signature is valid by determining the hash value in the signature using the s...
Contains parameters that are passed to the cryptographic service provider (CSP) that performs cryptog...
Definition: CspParameters.cs:8
Represents the base class from which all implementations of cryptographic hash algorithms must derive...
Definition: HashAlgorithm.cs:8
KeyContainerPermissionFlags
Specifies the type of key container access allowed.
Specifies the padding mode and parameters to use with RSA signature creation or verification operatio...
override byte [] Decrypt(byte[] data, RSAEncryptionPadding padding)
Decrypts data that was previously encrypted with the T:System.Security.Cryptography....
static RSASignaturePadding Pkcs1
Gets an object that uses the PKCS #1 v1.5 padding mode.
CharSet
Dictates which character set marshaled strings should use.
Definition: CharSet.cs:7
override byte [] DecryptValue(byte[] rgb)
This method is not supported in the current version.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
byte [] Q
Represents the Q parameter for the T:System.Security.Cryptography.RSA algorithm.
override RSAParameters ExportParameters(bool includePrivateParameters)
Exports the T:System.Security.Cryptography.RSAParameters.
byte [] SignData(Stream inputStream, object halg)
Computes the hash value of the specified input stream using the specified hash algorithm,...
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
Represents the base class from which all implementations of the T:System.Security....
Definition: RSA.cs:10
byte [] DP
Represents the DP parameter for the T:System.Security.Cryptography.RSA algorithm.
Provides additional information about a cryptographic key pair. This class cannot be inherited.
override void ImportParameters(RSAParameters parameters)
Imports the specified T:System.Security.Cryptography.RSAParameters.
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
bool VerifyData(byte[] buffer, object halg, byte[] signature)
Verifies that a digital signature is valid by determining the hash value in the signature using the p...
CspKeyContainerInfo CspKeyContainerInfo
Gets a T:System.Security.Cryptography.CspKeyContainerInfo object that describes additional informatio...
byte [] Decrypt(byte[] rgb, bool fOAEP)
Decrypts data with the T:System.Security.Cryptography.RSA algorithm.
override string KeyExchangeAlgorithm
Gets the name of the key exchange algorithm available with this implementation of T:System....
byte [] Exponent
Represents the Exponent parameter for the T:System.Security.Cryptography.RSA algorithm.
CspProviderFlags Flags
Represents the flags for T:System.Security.Cryptography.CspParameters that modify the behavior of the...
static RSAEncryptionPadding Pkcs1
Gets an object that represents the PKCS #1 encryption standard.
bool RandomlyGenerated
Gets a value indicating whether a key container was randomly generated by a managed cryptography clas...
byte [] ComputeHash(Stream inputStream)
Computes the hash value for the specified T:System.IO.Stream object.
byte [] SignData(byte[] buffer, object halg)
Computes the hash value of the specified byte array using the specified hash algorithm,...
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....
Definition: Stream.cs:16