2008-08-05 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Tue, 5 Aug 2008 20:38:43 +0000 (20:38 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Tue, 5 Aug 2008 20:38:43 +0000 (20:38 -0000)
* CryptoTools.cs: Make this usable with Silverlight 2.0 (NET_2_1)

svn path=/trunk/mcs/; revision=109705

mcs/class/corlib/Mono.Security.Cryptography/ChangeLog
mcs/class/corlib/Mono.Security.Cryptography/CryptoTools.cs

index 161f440f716fcfd92e5d1dd9a84be68ea80d08ea..c1c0cccd5e21a75e40cb1e2e018f190d7a77b5ef 100644 (file)
@@ -1,3 +1,7 @@
+2008-08-05  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * CryptoTools.cs: Make this usable with Silverlight 2.0 (NET_2_1)
+
 2008-04-21  Sebastien Pouliot  <sebastien@ximian.com>
 
        * CryptoConvert.cs: Fix HMAC to respect start index inside an array.
index 444e15df7d094715f9c096d1200d221bf35cb882..6c1775bebcd144ba46c805e68319a6583090ef9b 100644 (file)
@@ -6,11 +6,7 @@
 //     Sebastien Pouliot <sebastien@ximian.com>
 //
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004, 2008 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -49,24 +45,31 @@ namespace Mono.Security.Cryptography {
                private KeyBuilder ()
                {
                }
+
+               static RandomNumberGenerator Rng {
+                       get {
+#if NET_2_1
+                               if (rng == null)
+                                       rng = new RNGCryptoServiceProvider ();
+#else
+                               if (rng == null)
+                                       rng = RandomNumberGenerator.Create ();
+#endif
+                               return rng;
+                       }
+               }
        
                static public byte[] Key (int size) 
                {
-                       if (rng == null)
-                               rng = RandomNumberGenerator.Create ();
-
                        byte[] key = new byte [size];
-                       rng.GetBytes (key);
+                       Rng.GetBytes (key);
                        return key;
                }
        
                static public byte[] IV (int size) 
                {
-                       if (rng == null)
-                               rng = RandomNumberGenerator.Create ();
-
                        byte[] iv = new byte [size];
-                       rng.GetBytes (iv);
+                       Rng.GetBytes (iv);
                        return iv;
                }
        }