mscorlib(4.0.0.0) API with additions
RNGCryptoServiceProvider.cs
2 
4 {
6  [ComVisible(true)]
8  {
9  [SecurityCritical]
10  private SafeProvHandle m_safeProvHandle;
11 
12  private bool m_ownsHandle;
13 
16  : this((CspParameters)null)
17  {
18  }
19 
22  public RNGCryptoServiceProvider(string str)
23  : this((CspParameters)null)
24  {
25  }
26 
29  public RNGCryptoServiceProvider(byte[] rgb)
30  : this((CspParameters)null)
31  {
32  }
33 
36  [SecuritySafeCritical]
38  {
39  if (cspParams != null)
40  {
41  m_safeProvHandle = Utils.AcquireProvHandle(cspParams);
42  m_ownsHandle = true;
43  }
44  else
45  {
46  m_safeProvHandle = Utils.StaticProvHandle;
47  m_ownsHandle = false;
48  }
49  }
50 
51  [SecuritySafeCritical]
52  protected override void Dispose(bool disposing)
53  {
54  base.Dispose(disposing);
55  if (disposing && m_ownsHandle)
56  {
57  m_safeProvHandle.Dispose();
58  }
59  }
60 
66  [SecuritySafeCritical]
67  public override void GetBytes(byte[] data)
68  {
69  if (data == null)
70  {
71  throw new ArgumentNullException("data");
72  }
73  GetBytes(m_safeProvHandle, data, data.Length);
74  }
75 
81  [SecuritySafeCritical]
82  public override void GetNonZeroBytes(byte[] data)
83  {
84  if (data == null)
85  {
86  throw new ArgumentNullException("data");
87  }
88  GetNonZeroBytes(m_safeProvHandle, data, data.Length);
89  }
90 
91  [DllImport("QCall", CharSet = CharSet.Unicode)]
92  [SecurityCritical]
93  [SuppressUnmanagedCodeSecurity]
94  private static extern void GetBytes(SafeProvHandle hProv, byte[] randomBytes, int count);
95 
96  [DllImport("QCall", CharSet = CharSet.Unicode)]
97  [SecurityCritical]
98  [SuppressUnmanagedCodeSecurity]
99  private static extern void GetNonZeroBytes(SafeProvHandle hProv, byte[] randomBytes, int count);
100  }
101 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Definition: __Canon.cs:3
RNGCryptoServiceProvider(string str)
Initializes a new instance of the T:System.Security.Cryptography.RNGCryptoServiceProvider class.
override void GetBytes(byte[] data)
Fills an array of bytes with a cryptographically strong sequence of random values.
RNGCryptoServiceProvider(byte[] rgb)
Initializes a new instance of the T:System.Security.Cryptography.RNGCryptoServiceProvider class.
Implements a cryptographic Random Number Generator (RNG) using the implementation provided by the cry...
override void Dispose(bool disposing)
When overridden in a derived class, releases the unmanaged resources used by the T:System....
Contains parameters that are passed to the cryptographic service provider (CSP) that performs cryptog...
Definition: CspParameters.cs:8
RNGCryptoServiceProvider(CspParameters cspParams)
Initializes a new instance of the T:System.Security.Cryptography.RNGCryptoServiceProvider class with ...
CharSet
Dictates which character set marshaled strings should use.
Definition: CharSet.cs:7
override void GetNonZeroBytes(byte[] data)
Fills an array of bytes with a cryptographically strong sequence of random nonzero values.
Represents the abstract class from which all implementations of cryptographic random number generator...
RNGCryptoServiceProvider()
Initializes a new instance of the T:System.Security.Cryptography.RNGCryptoServiceProvider class.