| @@ -39,19 +39,19 @@ namespace GSF.Security.Cryptography · 38 unmodified lines |
| 39 | 39 | /// </summary> |
| 40 | 40 | public static class Random |
| 41 | 41 | { |
| 42 | | − private static readonly RNGCryptoServiceProvider s_randomNumberGenerator = new RNGCryptoServiceProvider(); |
| 42 | + private static readonly RNGCryptoServiceProvider RandomNumberGenerator = new RNGCryptoServiceProvider(); |
| 43 | 43 | |
| 44 | 44 | /// <summary> |
| 45 | 45 | /// Generates a cryptographically strong double-precision floating-point random number between zero and one. |
| 46 | 46 | /// </summary> |
| 47 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 47 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 48 | 48 | public static double Number |
| 49 | 49 | { |
| 50 | 50 | get |
| 51 | 51 | { |
| 52 | 52 | unchecked |
| 53 | 53 | { |
| 54 | | − return (double)UInt32 / (double)uint.MaxValue; |
| 54 | + return UInt32 / (uint.MaxValue + 1.0D); |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | } |
| @@ -59,14 +59,14 @@ namespace GSF.Security.Cryptography · 1 unmodified line |
| 59 | 59 | /// <summary> |
| 60 | 60 | /// Generates a cryptographically strong random decimal between zero and one. |
| 61 | 61 | /// </summary> |
| 62 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 62 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 63 | 63 | public static decimal Decimal |
| 64 | 64 | { |
| 65 | 65 | get |
| 66 | 66 | { |
| 67 | 67 | unchecked |
| 68 | 68 | { |
| 69 | | − return (decimal)UInt64 / (decimal)ulong.MaxValue; |
| 69 | + return UInt64 / (ulong.MaxValue + 1.0M); |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | } |
| @@ -76,7 +76,7 @@ namespace GSF.Security.Cryptography · 3 unmodified lines |
| 76 | 76 | /// </summary> |
| 77 | 77 | /// <param name="startNumber">A <see cref="double"/> that is the low end of our range.</param> |
| 78 | 78 | /// <param name="stopNumber">A <see cref="double"/> that is the high end of our range.</param> |
| 79 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 79 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 80 | 80 | /// <returns>A <see cref="double"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>, or an excception.</returns> |
| 81 | 81 | public static double Between(double startNumber, double stopNumber) |
| 82 | 82 | { |
| @@ -94,24 +94,24 @@ namespace GSF.Security.Cryptography · 11 unmodified lines |
| 94 | 94 | /// <para>The length of the byte array determines how many cryptographically strong random bytes are produced.</para> |
| 95 | 95 | /// <para>This method is thread safe.</para> |
| 96 | 96 | /// </remarks> |
| 97 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 98 | | − /// <exception cref="System.ArgumentNullException">buffer is null.</exception> |
| 97 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 98 | + /// <exception cref="ArgumentNullException">buffer is null.</exception> |
| 99 | 99 | public static void GetBytes(byte[] buffer) |
| 100 | 100 | { |
| 101 | | − s_randomNumberGenerator.GetBytes(buffer); |
| 101 | + RandomNumberGenerator.GetBytes(buffer); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /// <summary> |
| 105 | 105 | /// Generates a cryptographically strong random boolean (i.e., a coin toss). |
| 106 | 106 | /// </summary> |
| 107 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 107 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 108 | 108 | public static bool Boolean |
| 109 | 109 | { |
| 110 | 110 | get |
| 111 | 111 | { |
| 112 | 112 | byte[] value = new byte[1]; |
| 113 | 113 | |
| 114 | | − s_randomNumberGenerator.GetBytes(value); |
| 114 | + RandomNumberGenerator.GetBytes(value); |
| 115 | 115 | |
| 116 | 116 | return value[0] % 2 == 0; |
| 117 | 117 | } |
| @@ -120,14 +120,14 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 120 | 120 | /// <summary> |
| 121 | 121 | /// Generates a cryptographically strong 8-bit random integer. |
| 122 | 122 | /// </summary> |
| 123 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 123 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 124 | 124 | public static byte Byte |
| 125 | 125 | { |
| 126 | 126 | get |
| 127 | 127 | { |
| 128 | 128 | byte[] value = new byte[1]; |
| 129 | 129 | |
| 130 | | − s_randomNumberGenerator.GetBytes(value); |
| 130 | + RandomNumberGenerator.GetBytes(value); |
| 131 | 131 | |
| 132 | 132 | return value[0]; |
| 133 | 133 | } |
| @@ -136,7 +136,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 136 | 136 | /// <summary> |
| 137 | 137 | /// Generates a cryptographically strong 8-bit random integer between specified values. |
| 138 | 138 | /// </summary> |
| 139 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 139 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 140 | 140 | /// <param name="startNumber">A <see cref="byte"/> that is the low end of our range.</param> |
| 141 | 141 | /// <param name="stopNumber">A <see cref="byte"/> that is the high end of our range.</param> |
| 142 | 142 | /// <returns>A <see cref="byte"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -151,14 +151,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 151 | 151 | /// <summary> |
| 152 | 152 | /// Generates a cryptographically strong 16-bit random integer. |
| 153 | 153 | /// </summary> |
| 154 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 154 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 155 | 155 | public static short Int16 |
| 156 | 156 | { |
| 157 | 157 | get |
| 158 | 158 | { |
| 159 | 159 | byte[] value = new byte[2]; |
| 160 | 160 | |
| 161 | | − s_randomNumberGenerator.GetBytes(value); |
| 161 | + RandomNumberGenerator.GetBytes(value); |
| 162 | 162 | |
| 163 | 163 | return BitConverter.ToInt16(value, 0); |
| 164 | 164 | } |
| @@ -167,7 +167,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 167 | 167 | /// <summary> |
| 168 | 168 | /// Generates a cryptographically strong 16-bit random integer between specified values. |
| 169 | 169 | /// </summary> |
| 170 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 170 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 171 | 171 | /// <param name="startNumber">A <see cref="short"/> that is the low end of our range.</param> |
| 172 | 172 | /// <param name="stopNumber">A <see cref="short"/> that is the high end of our range.</param> |
| 173 | 173 | /// <returns>A <see cref="short"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -182,14 +182,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 182 | 182 | /// <summary> |
| 183 | 183 | /// Generates a cryptographically strong unsigned 16-bit random integer. |
| 184 | 184 | /// </summary> |
| 185 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 185 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 186 | 186 | public static ushort UInt16 |
| 187 | 187 | { |
| 188 | 188 | get |
| 189 | 189 | { |
| 190 | 190 | byte[] value = new byte[2]; |
| 191 | 191 | |
| 192 | | − s_randomNumberGenerator.GetBytes(value); |
| 192 | + RandomNumberGenerator.GetBytes(value); |
| 193 | 193 | |
| 194 | 194 | return BitConverter.ToUInt16(value, 0); |
| 195 | 195 | } |
| @@ -198,7 +198,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 198 | 198 | /// <summary> |
| 199 | 199 | /// Generates a cryptographically strong unsigned 16-bit random integer between specified values. |
| 200 | 200 | /// </summary> |
| 201 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 201 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 202 | 202 | /// <param name="startNumber">A <see cref="ushort"/> that is the low end of our range.</param> |
| 203 | 203 | /// <param name="stopNumber">A <see cref="ushort"/> that is the high end of our range.</param> |
| 204 | 204 | /// <returns>A <see cref="ushort"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -213,14 +213,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 213 | 213 | /// <summary> |
| 214 | 214 | /// Generates a cryptographically strong 24-bit random integer. |
| 215 | 215 | /// </summary> |
| 216 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 216 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 217 | 217 | public static Int24 Int24 |
| 218 | 218 | { |
| 219 | 219 | get |
| 220 | 220 | { |
| 221 | 221 | byte[] value = new byte[3]; |
| 222 | 222 | |
| 223 | | − s_randomNumberGenerator.GetBytes(value); |
| 223 | + RandomNumberGenerator.GetBytes(value); |
| 224 | 224 | |
| 225 | 225 | return Int24.GetValue(value, 0); |
| 226 | 226 | } |
| @@ -229,7 +229,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 229 | 229 | /// <summary> |
| 230 | 230 | /// Generates a cryptographically strong 24-bit random integer between specified values. |
| 231 | 231 | /// </summary> |
| 232 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 232 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 233 | 233 | /// <param name="startNumber">A <see cref="Int24"/> that is the low end of our range.</param> |
| 234 | 234 | /// <param name="stopNumber">A <see cref="Int24"/> that is the high end of our range.</param> |
| 235 | 235 | /// <returns>A <see cref="Int24"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -244,14 +244,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 244 | 244 | /// <summary> |
| 245 | 245 | /// Generates a cryptographically strong unsigned 24-bit random integer. |
| 246 | 246 | /// </summary> |
| 247 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 247 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 248 | 248 | public static UInt24 UInt24 |
| 249 | 249 | { |
| 250 | 250 | get |
| 251 | 251 | { |
| 252 | 252 | byte[] value = new byte[3]; |
| 253 | 253 | |
| 254 | | − s_randomNumberGenerator.GetBytes(value); |
| 254 | + RandomNumberGenerator.GetBytes(value); |
| 255 | 255 | |
| 256 | 256 | return UInt24.GetValue(value, 0); |
| 257 | 257 | } |
| @@ -260,7 +260,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 260 | 260 | /// <summary> |
| 261 | 261 | /// Generates a cryptographically strong unsigned 24-bit random integer between specified values. |
| 262 | 262 | /// </summary> |
| 263 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 263 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 264 | 264 | /// <param name="startNumber">A <see cref="UInt24"/> that is the low end of our range.</param> |
| 265 | 265 | /// <param name="stopNumber">A <see cref="UInt24"/> that is the high end of our range.</param> |
| 266 | 266 | /// <returns>A <see cref="UInt24"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -275,14 +275,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 275 | 275 | /// <summary> |
| 276 | 276 | /// Generates a cryptographically strong 32-bit random integer. |
| 277 | 277 | /// </summary> |
| 278 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 278 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 279 | 279 | public static int Int32 |
| 280 | 280 | { |
| 281 | 281 | get |
| 282 | 282 | { |
| 283 | 283 | byte[] value = new byte[4]; |
| 284 | 284 | |
| 285 | | − s_randomNumberGenerator.GetBytes(value); |
| 285 | + RandomNumberGenerator.GetBytes(value); |
| 286 | 286 | |
| 287 | 287 | return BitConverter.ToInt32(value, 0); |
| 288 | 288 | } |
| @@ -291,7 +291,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 291 | 291 | /// <summary> |
| 292 | 292 | /// Generates a cryptographically strong 32-bit random integer between specified values. |
| 293 | 293 | /// </summary> |
| 294 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 294 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 295 | 295 | /// <param name="startNumber">A <see cref="int"/> that is the low end of our range.</param> |
| 296 | 296 | /// <param name="stopNumber">A <see cref="int"/> that is the high end of our range.</param> |
| 297 | 297 | /// <returns>A <see cref="int"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -306,14 +306,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 306 | 306 | /// <summary> |
| 307 | 307 | /// Generates a cryptographically strong unsigned 32-bit random integer. |
| 308 | 308 | /// </summary> |
| 309 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 309 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 310 | 310 | public static uint UInt32 |
| 311 | 311 | { |
| 312 | 312 | get |
| 313 | 313 | { |
| 314 | 314 | byte[] value = new byte[4]; |
| 315 | 315 | |
| 316 | | − s_randomNumberGenerator.GetBytes(value); |
| 316 | + RandomNumberGenerator.GetBytes(value); |
| 317 | 317 | |
| 318 | 318 | return BitConverter.ToUInt32(value, 0); |
| 319 | 319 | } |
| @@ -322,7 +322,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 322 | 322 | /// <summary> |
| 323 | 323 | /// Generates a cryptographically strong unsigned 32-bit random integer between specified values. |
| 324 | 324 | /// </summary> |
| 325 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 325 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 326 | 326 | /// <param name="startNumber">A <see cref="uint"/> that is the low end of our range.</param> |
| 327 | 327 | /// <param name="stopNumber">A <see cref="uint"/> that is the high end of our range.</param> |
| 328 | 328 | /// <returns>A <see cref="uint"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -337,14 +337,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 337 | 337 | /// <summary> |
| 338 | 338 | /// Generates a cryptographically strong 64-bit random integer. |
| 339 | 339 | /// </summary> |
| 340 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 340 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 341 | 341 | public static long Int64 |
| 342 | 342 | { |
| 343 | 343 | get |
| 344 | 344 | { |
| 345 | 345 | byte[] value = new byte[8]; |
| 346 | 346 | |
| 347 | | − s_randomNumberGenerator.GetBytes(value); |
| 347 | + RandomNumberGenerator.GetBytes(value); |
| 348 | 348 | |
| 349 | 349 | return BitConverter.ToInt64(value, 0); |
| 350 | 350 | } |
| @@ -353,7 +353,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 353 | 353 | /// <summary> |
| 354 | 354 | /// Generates a cryptographically strong 64-bit random integer between specified values. |
| 355 | 355 | /// </summary> |
| 356 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 356 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 357 | 357 | /// <param name="startNumber">A <see cref="long"/> that is the low end of our range.</param> |
| 358 | 358 | /// <param name="stopNumber">A <see cref="long"/> that is the high end of our range.</param> |
| 359 | 359 | /// <returns>A <see cref="long"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -368,14 +368,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 368 | 368 | /// <summary> |
| 369 | 369 | /// Generates a cryptographically strong unsigned 64-bit random integer. |
| 370 | 370 | /// </summary> |
| 371 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 371 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 372 | 372 | public static ulong UInt64 |
| 373 | 373 | { |
| 374 | 374 | get |
| 375 | 375 | { |
| 376 | 376 | byte[] value = new byte[8]; |
| 377 | 377 | |
| 378 | | − s_randomNumberGenerator.GetBytes(value); |
| 378 | + RandomNumberGenerator.GetBytes(value); |
| 379 | 379 | |
| 380 | 380 | return BitConverter.ToUInt64(value, 0); |
| 381 | 381 | } |
| @@ -384,7 +384,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 384 | 384 | /// <summary> |
| 385 | 385 | /// Generates a cryptographically strong unsigned 64-bit random integer between specified values. |
| 386 | 386 | /// </summary> |
| 387 | | − /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 387 | + /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 388 | 388 | /// <param name="startNumber">A <see cref="ulong"/> that is the low end of our range.</param> |
| 389 | 389 | /// <param name="stopNumber">A <see cref="ulong"/> that is the high end of our range.</param> |
| 390 | 390 | /// <returns>A <see cref="ulong"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |