3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // <OWNER>[....]</OWNER>
10 // RandomNumberGenerator.cs
13 namespace System.Security.Cryptography {
14 #if !FEATURE_CORECLR && !SILVERLIGHT
15 [System.Runtime.InteropServices.ComVisible(true)]
16 #endif // !FEATURE_CORECLR && !SILVERLIGHT
17 public abstract class RandomNumberGenerator
18 // On Orcas RandomNumberGenerator is not disposable, so we cannot add the IDisposable implementation to the
19 // CoreCLR mscorlib. However, this type does need to be disposable since subtypes can and do hold onto
20 // native resources. Therefore, on desktop mscorlibs we add an IDisposable implementation.
23 #endif // !FEATURE_CORECLR
25 protected RandomNumberGenerator() {
32 #if (!FEATURE_CORECLR && !SILVERLIGHT) || FEATURE_LEGACYNETCFCRYPTO
33 static public RandomNumberGenerator Create() {
34 return Create("System.Security.Cryptography.RandomNumberGenerator");
37 static public RandomNumberGenerator Create(String rngName) {
38 return (RandomNumberGenerator) CryptoConfig.CreateFromName(rngName);
40 #endif // (!FEATURE_CORECLR && !SILVERLIGHT) || FEATURE_LEGACYNETCFCRYPTO
42 public void Dispose() {
44 GC.SuppressFinalize(this);
47 protected virtual void Dispose(bool disposing) {
51 public abstract void GetBytes(byte[] data);
53 #if (!FEATURE_CORECLR && !SILVERLIGHT) || FEATURE_LEGACYNETCFCRYPTO
54 public virtual void GetNonZeroBytes(byte[] data)
56 // This method does not exist on Silverlight, so for compatibility we cannot have it be abstract
57 // on the desktop (otherwise any type deriving from RandomNumberGenerator on Silverlight cannot
58 // compile against the desktop CLR). Since this technically is an abstract method with no
59 // implementation, we'll just throw NotImplementedException.
60 throw new NotImplementedException();
62 #endif // (!FEATURE_CORECLR && !SILVERLIGHT) || FEATURE_LEGACYNETCFCRYPTO