diff --git a/snippets/cpp/VS_Snippets_CLR/Cryptography.PasswordDerivedbytes/cpp/sample.cpp b/snippets/cpp/VS_Snippets_CLR/Cryptography.PasswordDerivedbytes/cpp/sample.cpp index eba4a79c828..06b5a8483db 100644 --- a/snippets/cpp/VS_Snippets_CLR/Cryptography.PasswordDerivedbytes/cpp/sample.cpp +++ b/snippets/cpp/VS_Snippets_CLR/Cryptography.PasswordDerivedbytes/cpp/sample.cpp @@ -18,12 +18,12 @@ array^ CreateRandomSalt(int length) randomBytes = gcnew array (1); } - // Create a new RNGCryptoServiceProvider. - RNGCryptoServiceProvider^ cryptoRNGProvider = - gcnew RNGCryptoServiceProvider(); + // Create a new RandomNumberGenerator. + RandomNumberGenerator^ randomNumberGenerator = + RandomNumberGenerator::Create(); // Fill the buffer with random bytes. - cryptoRNGProvider->GetBytes(randomBytes); + randomNumberGenerator->GetBytes(randomBytes); // return the bytes. return randomBytes; diff --git a/snippets/cpp/VS_Snippets_CLR/HMACRIPEMD160/CPP/hmacripemd160.cpp b/snippets/cpp/VS_Snippets_CLR/HMACRIPEMD160/CPP/hmacripemd160.cpp index 3a6a3d6403c..0f9f1c2f6ac 100644 --- a/snippets/cpp/VS_Snippets_CLR/HMACRIPEMD160/CPP/hmacripemd160.cpp +++ b/snippets/cpp/VS_Snippets_CLR/HMACRIPEMD160/CPP/hmacripemd160.cpp @@ -111,8 +111,7 @@ int main() // secret key shared by sender and receiver. array^secretkey = gcnew array(64); - //RNGCryptoServiceProvider is an implementation of a random number generator. - RNGCryptoServiceProvider^ rng = gcnew RNGCryptoServiceProvider; + RandomNumberGenerator^ rng = RandomNumberGenerator::Create(); // The array is now filled with cryptographically strong random bytes. rng->GetBytes( secretkey ); diff --git a/snippets/cpp/VS_Snippets_CLR/HMACRIPEMD160/CPP/makefile b/snippets/cpp/VS_Snippets_CLR/HMACRIPEMD160/CPP/makefile new file mode 100644 index 00000000000..35f08e9adb2 --- /dev/null +++ b/snippets/cpp/VS_Snippets_CLR/HMACRIPEMD160/CPP/makefile @@ -0,0 +1,2 @@ +System.Security.Cryptography.HMACRIPEMD160.exe: hmacripemd160.cpp + cl /FeSystem.Security.Cryptography.HMACRIPEMD160.exe /clr:pure hmacripemd160.cpp diff --git a/snippets/cpp/VS_Snippets_CLR/HMACSHA256/CPP/hmacsha256.cpp b/snippets/cpp/VS_Snippets_CLR/HMACSHA256/CPP/hmacsha256.cpp index 72688544c68..d26844e8082 100644 --- a/snippets/cpp/VS_Snippets_CLR/HMACSHA256/CPP/hmacsha256.cpp +++ b/snippets/cpp/VS_Snippets_CLR/HMACSHA256/CPP/hmacsha256.cpp @@ -111,8 +111,7 @@ int main() // secret key shared by sender and receiver. array^secretkey = gcnew array(64); - //RNGCryptoServiceProvider is an implementation of a random number generator. - RNGCryptoServiceProvider^ rng = gcnew RNGCryptoServiceProvider; + RandomNumberGenerator^ rng = RandomNumberGenerator::Create(); // The array is now filled with cryptographically strong random bytes. rng->GetBytes( secretkey ); diff --git a/snippets/cpp/VS_Snippets_CLR/HMACSHA256/CPP/makefile b/snippets/cpp/VS_Snippets_CLR/HMACSHA256/CPP/makefile new file mode 100644 index 00000000000..c5caba97392 --- /dev/null +++ b/snippets/cpp/VS_Snippets_CLR/HMACSHA256/CPP/makefile @@ -0,0 +1,2 @@ +System.Security.Cryptography.HMACSHA256.exe: hmacsha256.cpp + cl /FeSystem.Security.Cryptography.HMACSHA256.exe /clr:pure hmacsha256.cpp diff --git a/snippets/cpp/VS_Snippets_CLR/HMACSHA384/CPP/hmacsha384.cpp b/snippets/cpp/VS_Snippets_CLR/HMACSHA384/CPP/hmacsha384.cpp index 0ae778597be..6dfcd8a29fa 100644 --- a/snippets/cpp/VS_Snippets_CLR/HMACSHA384/CPP/hmacsha384.cpp +++ b/snippets/cpp/VS_Snippets_CLR/HMACSHA384/CPP/hmacsha384.cpp @@ -111,8 +111,7 @@ int main() // secret key shared by sender and receiver. array^secretkey = gcnew array(64); - //RNGCryptoServiceProvider is an implementation of a random number generator. - RNGCryptoServiceProvider^ rng = gcnew RNGCryptoServiceProvider; + RandomNumberGenerator^ rng = RandomNumberGenerator::Create(); // The array is now filled with cryptographically strong random bytes. rng->GetBytes( secretkey ); diff --git a/snippets/cpp/VS_Snippets_CLR/HMACSHA384/CPP/makefile b/snippets/cpp/VS_Snippets_CLR/HMACSHA384/CPP/makefile new file mode 100644 index 00000000000..3e26e510700 --- /dev/null +++ b/snippets/cpp/VS_Snippets_CLR/HMACSHA384/CPP/makefile @@ -0,0 +1,2 @@ +System.Security.Cryptography.HMACSHA384.exe: hmacsha384.cpp + cl /FeSystem.Security.Cryptography.HMACSHA384.exe /clr:pure hmacsha384.cpp diff --git a/snippets/cpp/VS_Snippets_CLR/HMACSHA512/CPP/hmacsha512.cpp b/snippets/cpp/VS_Snippets_CLR/HMACSHA512/CPP/hmacsha512.cpp index 4683aaa6838..4f83ce4b8b5 100644 --- a/snippets/cpp/VS_Snippets_CLR/HMACSHA512/CPP/hmacsha512.cpp +++ b/snippets/cpp/VS_Snippets_CLR/HMACSHA512/CPP/hmacsha512.cpp @@ -110,9 +110,8 @@ int main() // Create a random key using a random number generator. This would be the // secret key shared by sender and receiver. array^secretkey = gcnew array(64); - - //RNGCryptoServiceProvider is an implementation of a random number generator. - RNGCryptoServiceProvider^ rng = gcnew RNGCryptoServiceProvider; + + RandomNumberGenerator^ rng = RandomNumberGenerator::Create(); // The array is now filled with cryptographically strong random bytes. rng->GetBytes( secretkey ); diff --git a/snippets/cpp/VS_Snippets_CLR/HMACSHA512/CPP/makefile b/snippets/cpp/VS_Snippets_CLR/HMACSHA512/CPP/makefile new file mode 100644 index 00000000000..24ac11a57ac --- /dev/null +++ b/snippets/cpp/VS_Snippets_CLR/HMACSHA512/CPP/makefile @@ -0,0 +1,2 @@ +System.Security.Cryptography.HMACSHA512.exe: hmacsha512.cpp + cl /FeSystem.Security.Cryptography.HMACSHA512.exe /clr:pure hmacsha512.cpp diff --git a/snippets/cpp/VS_Snippets_CLR/rfc28981/CPP/rfc28981.cpp b/snippets/cpp/VS_Snippets_CLR/rfc28981/CPP/rfc28981.cpp index cd03e6be098..0494e4ad274 100644 --- a/snippets/cpp/VS_Snippets_CLR/rfc28981/CPP/rfc28981.cpp +++ b/snippets/cpp/VS_Snippets_CLR/rfc28981/CPP/rfc28981.cpp @@ -27,8 +27,8 @@ int main() String^ pwd1 = passwordargs[ 1 ]; array^salt1 = gcnew array(8); - RNGCryptoServiceProvider ^ rngCsp = gcnew RNGCryptoServiceProvider(); - rngCsp->GetBytes(salt1); + RandomNumberGenerator^ rng = RandomNumberGenerator::Create(); + rng->GetBytes(salt1); //data1 can be a string or contents of a file. String^ data1 = "Some test data"; diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetBytes Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetBytes Example/CPP/source.cpp index 8fa7d638842..9d881778d4a 100644 --- a/snippets/cpp/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetBytes Example/CPP/source.cpp +++ b/snippets/cpp/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetBytes Example/CPP/source.cpp @@ -16,8 +16,7 @@ public ref class Form1: public Form // array^ random = gcnew array(100); - //RNGCryptoServiceProvider is an implementation of a random number generator. - RNGCryptoServiceProvider^ rng = gcnew RNGCryptoServiceProvider; + RandomNumberGenerator^ rng = RandomNumberGenerator::Create(); rng->GetBytes( random ); // The array is now filled with cryptographically strong random bytes. // } diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetNonZeroBytes Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetNonZeroBytes Example/CPP/source.cpp index 81410bf4726..c9dcb18468c 100644 --- a/snippets/cpp/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetNonZeroBytes Example/CPP/source.cpp +++ b/snippets/cpp/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetNonZeroBytes Example/CPP/source.cpp @@ -15,8 +15,7 @@ public ref class Form1: public Form { // array^ random = gcnew array(100); - //RNGCryptoServiceProvider is an implementation of a random number generator. - RNGCryptoServiceProvider^ rng = gcnew RNGCryptoServiceProvider; + RandomNumberGenerator^ rng = RandomNumberGenerator::Create(); rng->GetNonZeroBytes( random ); // The array is now filled with cryptographically strong random bytes, and none are zero. // } diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.RSAOAEPKeyExchangeDeformatter/CPP/rsaencoder.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.RSAOAEPKeyExchangeDeformatter/CPP/rsaencoder.cpp index 204cd71a3fd..cb8ce0d69c9 100644 --- a/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.RSAOAEPKeyExchangeDeformatter/CPP/rsaencoder.cpp +++ b/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.RSAOAEPKeyExchangeDeformatter/CPP/rsaencoder.cpp @@ -122,7 +122,7 @@ ref class RSAEncoder // Create a random number using the RNGCryptoServiceProvider provider. // - RNGCryptoServiceProvider^ ring = gcnew RNGCryptoServiceProvider; + RandomNumberGenerator^ ring = RandomNumberGenerator::Create(); rsaFormatter->Rng = ring; // @@ -190,7 +190,7 @@ int main() // // Encoding the following message: // A phrase to be encoded. -// Resulting message encoded: %?}T:v??xu?eD)YucItjwu¦ALH HB,Uj??2xq?.?s45 +// Resulting message encoded: %?}T:v??xu?eD)YucItjwu¦ALH HB,Uj??2xq?.?s45 // ?f?L2?=X?CPzWx???"q5?6&N"AE,Z+T?(]S?_7~,?G{?VV!:S?df? // Resulting message decoded: // A phrase to be encoded. diff --git a/snippets/csharp/System.Security.Cryptography/HMACRIPEMD160/Overview/hmacripemd160.cs b/snippets/csharp/System.Security.Cryptography/HMACRIPEMD160/Overview/hmacripemd160.cs index 86565762842..c7d7252d9ca 100644 --- a/snippets/csharp/System.Security.Cryptography/HMACRIPEMD160/Overview/hmacripemd160.cs +++ b/snippets/csharp/System.Security.Cryptography/HMACRIPEMD160/Overview/hmacripemd160.cs @@ -35,8 +35,8 @@ public static void Main(string[] Fileargs) // Create a random key using a random number generator. This would be the // secret key shared by sender and receiver. byte[] secretkey = new Byte[64]; - //RNGCryptoServiceProvider is an implementation of a random number generator. - using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider()) + + using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { // The array is now filled with cryptographically strong random bytes. rng.GetBytes(secretkey); diff --git a/snippets/csharp/System.Security.Cryptography/HMACSHA256/Overview/hmacsha256.cs b/snippets/csharp/System.Security.Cryptography/HMACSHA256/Overview/hmacsha256.cs index d5ca7e5780c..ef5f5b8c10c 100644 --- a/snippets/csharp/System.Security.Cryptography/HMACSHA256/Overview/hmacsha256.cs +++ b/snippets/csharp/System.Security.Cryptography/HMACSHA256/Overview/hmacsha256.cs @@ -35,8 +35,8 @@ public static void Main(string[] Fileargs) // Create a random key using a random number generator. This would be the // secret key shared by sender and receiver. byte[] secretkey = new Byte[64]; - //RNGCryptoServiceProvider is an implementation of a random number generator. - using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider()) + + using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { // The array is now filled with cryptographically strong random bytes. rng.GetBytes(secretkey); diff --git a/snippets/csharp/System.Security.Cryptography/HMACSHA384/Overview/hmacsha384.cs b/snippets/csharp/System.Security.Cryptography/HMACSHA384/Overview/hmacsha384.cs index 8a6479c66e1..deccc5c0426 100644 --- a/snippets/csharp/System.Security.Cryptography/HMACSHA384/Overview/hmacsha384.cs +++ b/snippets/csharp/System.Security.Cryptography/HMACSHA384/Overview/hmacsha384.cs @@ -35,8 +35,8 @@ public static void Main(string[] Fileargs) // Create a random key using a random number generator. This would be the // secret key shared by sender and receiver. byte[] secretkey = new Byte[64]; - //RNGCryptoServiceProvider is an implementation of a random number generator. - using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider()) + + using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { // The array is now filled with cryptographically strong random bytes. rng.GetBytes(secretkey); diff --git a/snippets/csharp/System.Security.Cryptography/HMACSHA512/Overview/hmacsha512.cs b/snippets/csharp/System.Security.Cryptography/HMACSHA512/Overview/hmacsha512.cs index 8852867494c..fc1581c835f 100644 --- a/snippets/csharp/System.Security.Cryptography/HMACSHA512/Overview/hmacsha512.cs +++ b/snippets/csharp/System.Security.Cryptography/HMACSHA512/Overview/hmacsha512.cs @@ -35,8 +35,8 @@ public static void Main(string[] Fileargs) // Create a random key using a random number generator. This would be the // secret key shared by sender and receiver. byte[] secretkey = new Byte[64]; - //RNGCryptoServiceProvider is an implementation of a random number generator. - using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider()) + + using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { // The array is now filled with cryptographically strong random bytes. rng.GetBytes(secretkey); diff --git a/snippets/csharp/System.Security.Cryptography/MACTripleDES/Overview/program.cs b/snippets/csharp/System.Security.Cryptography/MACTripleDES/Overview/program.cs index 6a4614398b5..3990c201e8c 100644 --- a/snippets/csharp/System.Security.Cryptography/MACTripleDES/Overview/program.cs +++ b/snippets/csharp/System.Security.Cryptography/MACTripleDES/Overview/program.cs @@ -35,8 +35,8 @@ public static void Main(string[] Fileargs) // Create a random key using a random number generator. This would be the // secret key shared by sender and receiver. byte[] secretkey = new Byte[24]; - //RNGCryptoServiceProvider is an implementation of a random number generator. - using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider()) + + using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { // The array is now filled with cryptographically strong random bytes. rng.GetBytes(secretkey); diff --git a/snippets/csharp/System.Security.Cryptography/PasswordDeriveBytes/Overview/sample.cs b/snippets/csharp/System.Security.Cryptography/PasswordDeriveBytes/Overview/sample.cs index 7fad81cff78..429ac597a62 100644 --- a/snippets/csharp/System.Security.Cryptography/PasswordDeriveBytes/Overview/sample.cs +++ b/snippets/csharp/System.Security.Cryptography/PasswordDeriveBytes/Overview/sample.cs @@ -79,11 +79,11 @@ public static byte[] CreateRandomSalt(int length) randBytes = new byte[1]; } - // Create a new RNGCryptoServiceProvider. - RNGCryptoServiceProvider rand = new RNGCryptoServiceProvider(); - - // Fill the buffer with random bytes. - rand.GetBytes(randBytes); + using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) + { + // Fill the buffer with random bytes. + rng.GetBytes(randBytes); + } // return the bytes. return randBytes; diff --git a/snippets/csharp/System.Security.Cryptography/RSAOAEPKeyExchangeDeformatter/Parameters/rsaencoder.cs b/snippets/csharp/System.Security.Cryptography/RSAOAEPKeyExchangeDeformatter/Parameters/rsaencoder.cs index abf7ebac076..5aab9d4c1cb 100644 --- a/snippets/csharp/System.Security.Cryptography/RSAOAEPKeyExchangeDeformatter/Parameters/rsaencoder.cs +++ b/snippets/csharp/System.Security.Cryptography/RSAOAEPKeyExchangeDeformatter/Parameters/rsaencoder.cs @@ -122,9 +122,9 @@ private void ConstructFormatter() rsaFormatter.SetKey(key); // - // Create a random number using the RNGCryptoServiceProvider provider. + // Create a random number using the RandomNumberGenerator // - RNGCryptoServiceProvider ring = new RNGCryptoServiceProvider(); + RandomNumberGenerator ring = RandomNumberGenerator.Create(); rsaFormatter.Rng = ring; // diff --git a/snippets/csharp/System.Security.Cryptography/RandomNumberGenerator/GetBytes/source.cs b/snippets/csharp/System.Security.Cryptography/RandomNumberGenerator/GetBytes/source.cs index a81469c2fe2..a090085f5bd 100644 --- a/snippets/csharp/System.Security.Cryptography/RandomNumberGenerator/GetBytes/source.cs +++ b/snippets/csharp/System.Security.Cryptography/RandomNumberGenerator/GetBytes/source.cs @@ -1,18 +1,19 @@ using System; using System.Data; -using System.Security.Cryptography ; +using System.Security.Cryptography; using System.Windows.Forms; public class Form1: Form { public static void Main() { - // - byte[] random = new Byte[100]; + // + byte[] random = new byte[100]; - //RNGCryptoServiceProvider is an implementation of a random number generator. - RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); - rng.GetBytes(random); // The array is now filled with cryptographically strong random bytes. - // + using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) + { + rng.GetBytes(random); // The array is now filled with cryptographically strong random bytes. + } + // } } diff --git a/snippets/csharp/System.Security.Cryptography/RandomNumberGenerator/GetNonZeroBytes/source.cs b/snippets/csharp/System.Security.Cryptography/RandomNumberGenerator/GetNonZeroBytes/source.cs index c0c4650faed..99bd717cc20 100644 --- a/snippets/csharp/System.Security.Cryptography/RandomNumberGenerator/GetNonZeroBytes/source.cs +++ b/snippets/csharp/System.Security.Cryptography/RandomNumberGenerator/GetNonZeroBytes/source.cs @@ -8,10 +8,12 @@ public class Form1: Form public void Method() { // - byte[] random = new Byte[100]; - //RNGCryptoServiceProvider is an implementation of a random number generator. - RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); - rng.GetNonZeroBytes(random); // The array is now filled with cryptographically strong random bytes, and none are zero. + byte[] random = new byte[100]; + + using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) + { + rng.GetNonZeroBytes(random); // The array is now filled with cryptographically strong random bytes, and none are zero. + } // } } diff --git a/snippets/csharp/System.Security.Cryptography/Rfc2898DeriveBytes/Overview/rfc28981.cs b/snippets/csharp/System.Security.Cryptography/Rfc2898DeriveBytes/Overview/rfc28981.cs index 4f3849c8289..cae652faeff 100644 --- a/snippets/csharp/System.Security.Cryptography/Rfc2898DeriveBytes/Overview/rfc28981.cs +++ b/snippets/csharp/System.Security.Cryptography/Rfc2898DeriveBytes/Overview/rfc28981.cs @@ -26,11 +26,10 @@ public static void Main(string[] passwordargs) string pwd1 = passwordargs[0]; // Create a byte array to hold the random value. byte[] salt1 = new byte[8]; - using (RNGCryptoServiceProvider rngCsp = new -RNGCryptoServiceProvider()) + using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { // Fill the array with a random value. - rngCsp.GetBytes(salt1); + rng.GetBytes(salt1); } //data1 can be a string or contents of a file. diff --git a/snippets/csharp/VS_Snippets_CFX/samlattribute/cs/Project.csproj b/snippets/csharp/VS_Snippets_CFX/samlattribute/cs/Project.csproj new file mode 100644 index 00000000000..0f78fd26319 --- /dev/null +++ b/snippets/csharp/VS_Snippets_CFX/samlattribute/cs/Project.csproj @@ -0,0 +1,14 @@ + + + + Exe + net4.8 + + + + + + + + + diff --git a/snippets/csharp/VS_Snippets_CFX/samlattribute/cs/makefile b/snippets/csharp/VS_Snippets_CFX/samlattribute/cs/makefile deleted file mode 100644 index bddebecd28f..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/samlattribute/cs/makefile +++ /dev/null @@ -1,4 +0,0 @@ -all: source.exe - -source.exe: source.cs - csc /t:exe *.cs /r:System.dll,System.Configuration.dll,System.ServiceModel.dll,System.Runtime.Serialization.dll,System.IdentityModel.dll,System.Xml.dll, /lib:c:\whidbey\assemblies diff --git a/snippets/csharp/VS_Snippets_CFX/samlattribute/cs/source.cs b/snippets/csharp/VS_Snippets_CFX/samlattribute/cs/source.cs index 89bcb0a6d7e..2b238e5a29b 100644 --- a/snippets/csharp/VS_Snippets_CFX/samlattribute/cs/source.cs +++ b/snippets/csharp/VS_Snippets_CFX/samlattribute/cs/source.cs @@ -1,4 +1,4 @@ -//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- using System; @@ -80,7 +80,7 @@ protected override Collection GetIssuedClaims(RequestSecurityToke return samlAttributes; } // - public static void Main() {} + public static void Main() { } #region Helper Methods /// @@ -139,7 +139,7 @@ private static bool CheckIfPurchaseLimitMet(string bookID) return false; List claimsets = new List(authContext.ClaimSets); - ClaimSet myClaimSet = claimsets.Find((Predicate)delegate(ClaimSet target) + ClaimSet myClaimSet = claimsets.Find((Predicate)delegate (ClaimSet target) { X509CertificateClaimSet certClaimSet = target.Issuer as X509CertificateClaimSet; return certClaimSet != null && certClaimSet.X509Certificate.Subject == "CN=HomeRealmSTS.com"; @@ -247,8 +247,8 @@ private static bool IssuedByHomeRealmSTS(ClaimSet myClaimSet) /// Abstract base class for STS implementations. /// public abstract class SecurityTokenService : ISecurityTokenService - { - string stsName; // The name of the STS. Used to populate saml:Assertion/@Issuer + { + string stsName; // The name of the STS. Used to populate saml:Assertion/@Issuer SecurityToken issuerToken; // The SecurityToken used to sign issued tokens SecurityToken proofKeyEncryptionToken; // The SecurityToken used to encrypt the proof key in the issued token. @@ -289,7 +289,7 @@ protected SecurityToken ProofKeyEncryptionToken get { return this.proofKeyEncryptionToken; } } - #region Abstract methods + #region Abstract methods /// /// Abstract method for setting up claims in the SAML Token issued by the STS @@ -322,10 +322,14 @@ protected static void EnsureRequestSecurityTokenAction(Message message) protected static BinarySecretSecurityToken CreateProofToken(int keySize) { // Create an array to store the key bytes. - byte[] key = new byte[keySize/8]; + byte[] key = new byte[keySize / 8]; + // Create some random bytes. - RNGCryptoServiceProvider random = new RNGCryptoServiceProvider(); - random.GetNonZeroBytes(key); + using (RandomNumberGenerator random = RandomNumberGenerator.Create()) + { + random.GetNonZeroBytes(key); + } + // Create a BinarySecretSecurityToken from the random bytes and return it. return new BinarySecretSecurityToken(key); } @@ -409,9 +413,12 @@ public virtual Message ProcessRequestSecurityToken(Message message) { // Create an array to store the entropy bytes. stsEntropy = new byte[keySize / 8]; + // Create some random bytes. - RNGCryptoServiceProvider random = new RNGCryptoServiceProvider(); - random.GetNonZeroBytes(stsEntropy); + using (RandomNumberGenerator random = RandomNumberGenerator.Create()) + { + random.GetNonZeroBytes(stsEntropy); + } // Compute the combined key. key = RequestSecurityTokenResponse.ComputeCombinedKey(senderEntropy, stsEntropy, keySize); } @@ -419,9 +426,12 @@ public virtual Message ProcessRequestSecurityToken(Message message) { // Create an array to store the entropy bytes. key = new byte[keySize / 8]; + // Create some random bytes. - RNGCryptoServiceProvider random = new RNGCryptoServiceProvider(); - random.GetNonZeroBytes(key); + using (RandomNumberGenerator random = RandomNumberGenerator.Create()) + { + random.GetNonZeroBytes(key); + } } // Create a BinarySecretSecurityToken to be the proof token, based on the key material @@ -846,14 +856,14 @@ private static EndpointAddress ProcessAppliesToElement(XmlReader xr) !xr.IsEmptyElement && XmlNodeType.Element == xr.NodeType) { - // + // // Create a DataContractSerializer for an EndpointAddress10. DataContractSerializer dcs = new DataContractSerializer(typeof(EndpointAddress10)); // Read the EndpointAddress10 from the DataContractSerializer. EndpointAddress10 ea10 = (EndpointAddress10)dcs.ReadObject(xr, false); // Convert the EndpointAddress10 into an EndpointAddress. ea = ea10.ToEndpointAddress(); - // + // } // Look for the end-tag that corresponds to the start-tag that the reader was positioned @@ -1064,7 +1074,7 @@ public static byte[] ComputeCombinedKey(byte[] requestorEntropy, byte[] issuerEn byte[] a = issuerEntropy; // A(0) byte[] b = new byte[kha.HashSize / 8 + a.Length]; // Buffer for A(i) + seed - for (int i = 0; i < key.Length; ) + for (int i = 0; i < key.Length;) { // Calculate A(i+1). kha.Initialize(); @@ -1348,20 +1358,20 @@ class ServiceConstants /// public static void LoadAppSettings() { -/* - BookDB = ConfigurationManager.AppSettings["bookDB"]; - CheckIfLoaded(BookDB); - BookDB = string.Format("{0}\\{1}", System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, BookDB); + /* + BookDB = ConfigurationManager.AppSettings["bookDB"]; + CheckIfLoaded(BookDB); + BookDB = string.Format("{0}\\{1}", System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, BookDB); - CertDistinguishedName = ConfigurationManager.AppSettings["certDistinguishedName"]; - CheckIfLoaded(CertDistinguishedName); + CertDistinguishedName = ConfigurationManager.AppSettings["certDistinguishedName"]; + CheckIfLoaded(CertDistinguishedName); - TargetDistinguishedName = ConfigurationManager.AppSettings["targetDistinguishedName"]; - CheckIfLoaded(TargetDistinguishedName); + TargetDistinguishedName = ConfigurationManager.AppSettings["targetDistinguishedName"]; + CheckIfLoaded(TargetDistinguishedName); - IssuerDistinguishedName = ConfigurationManager.AppSettings["issuerDistinguishedName"]; - CheckIfLoaded(IssuerDistinguishedName); - */ + IssuerDistinguishedName = ConfigurationManager.AppSettings["issuerDistinguishedName"]; + CheckIfLoaded(IssuerDistinguishedName); + */ } /// diff --git a/snippets/visualbasic/VS_Snippets_CFX/samlattribute/vb/source.vb b/snippets/visualbasic/VS_Snippets_CFX/samlattribute/vb/source.vb index 6871053d457..3edb9024cca 100644 --- a/snippets/visualbasic/VS_Snippets_CFX/samlattribute/vb/source.vb +++ b/snippets/visualbasic/VS_Snippets_CFX/samlattribute/vb/source.vb @@ -320,9 +320,12 @@ Namespace Microsoft.ServiceModel.Samples.Federation Protected Shared Function CreateProofToken(ByVal keySize As Integer) As BinarySecretSecurityToken ' Create an array to store the key bytes. Dim key(keySize / 8 - 1) As Byte + ' Create some random bytes. - Dim random As New RNGCryptoServiceProvider() - random.GetNonZeroBytes(key) + Using random As RandomNumberGenerator = RandomNumberGenerator.Create() + random.GetNonZeroBytes(key) + End Using + ' Create a BinarySecretSecurityToken from the random bytes and return it. Return New BinarySecretSecurityToken(key) End Function @@ -398,18 +401,23 @@ Namespace Microsoft.ServiceModel.Samples.Federation If Not (senderEntropy Is Nothing) Then ' Create an array to store the entropy bytes. stsEntropy = New Byte(keySize / 8) {} + ' Create some random bytes. - Dim random As New RNGCryptoServiceProvider() - random.GetNonZeroBytes(stsEntropy) + Using random As RandomNumberGenerator = RandomNumberGenerator.Create() + random.GetNonZeroBytes(stsEntropy) + End Using + ' Compute the combined key. key = RequestSecurityTokenResponse.ComputeCombinedKey(senderEntropy, stsEntropy, keySize) ' Issuer entropy only... Else ' Create an array to store the entropy bytes. key = New Byte(keySize / 8) {} + ' Create some random bytes. - Dim random As New RNGCryptoServiceProvider() - random.GetNonZeroBytes(key) + Using random As RandomNumberGenerator = RandomNumberGenerator.Create() + random.GetNonZeroBytes(key) + End Using End If ' Create a BinarySecretSecurityToken to be the proof token, based on the key material diff --git a/snippets/visualbasic/VS_Snippets_CLR/Cryptography.PasswordDerivedbytes/VB/sample.vb b/snippets/visualbasic/VS_Snippets_CLR/Cryptography.PasswordDerivedbytes/VB/sample.vb index 2344af9234b..611a25a8663 100644 --- a/snippets/visualbasic/VS_Snippets_CLR/Cryptography.PasswordDerivedbytes/VB/sample.vb +++ b/snippets/visualbasic/VS_Snippets_CLR/Cryptography.PasswordDerivedbytes/VB/sample.vb @@ -71,11 +71,11 @@ Module PasswordDerivedBytesExample randBytes = New Byte(0) {} End If - ' Create a new RNGCryptoServiceProvider. - Dim rand As New RNGCryptoServiceProvider() - - ' Fill the buffer with random bytes. - rand.GetBytes(randBytes) + ' Create a new RandomNumberGenerator. + Using rand As RandomNumberGenerator = RandomNumberGenerator.Create() + ' Fill the buffer with random bytes. + rand.GetBytes(randBytes) + End Using ' return the bytes. Return randBytes diff --git a/snippets/visualbasic/VS_Snippets_CLR/HMACRIPEMD160/vb/hmacripemd160.vb b/snippets/visualbasic/VS_Snippets_CLR/HMACRIPEMD160/vb/hmacripemd160.vb index 8e4eadd9ab7..0150a05e210 100644 --- a/snippets/visualbasic/VS_Snippets_CLR/HMACRIPEMD160/vb/hmacripemd160.vb +++ b/snippets/visualbasic/VS_Snippets_CLR/HMACRIPEMD160/vb/hmacripemd160.vb @@ -27,8 +27,8 @@ Public Class HMACRIPEMD160example ' Create a random key using a random number generator. This would be the ' secret key shared by sender and receiver. Dim secretkey() As Byte = New [Byte](63) {} - 'RNGCryptoServiceProvider is an implementation of a random number generator. - Using rng As New RNGCryptoServiceProvider() + + Using rng As RandomNumberGenerator = RandomNumberGenerator.Create() ' The array is now filled with cryptographically strong random bytes. rng.GetBytes(secretkey) diff --git a/snippets/visualbasic/VS_Snippets_CLR/HMACSHA256/vb/hmacsha256.vb b/snippets/visualbasic/VS_Snippets_CLR/HMACSHA256/vb/hmacsha256.vb index aa26942d9b2..361d5df38f0 100644 --- a/snippets/visualbasic/VS_Snippets_CLR/HMACSHA256/vb/hmacsha256.vb +++ b/snippets/visualbasic/VS_Snippets_CLR/HMACSHA256/vb/hmacsha256.vb @@ -27,8 +27,8 @@ Public Class HMACSHA256example ' Create a random key using a random number generator. This would be the ' secret key shared by sender and receiver. Dim secretkey() As Byte = New [Byte](63) {} - 'RNGCryptoServiceProvider is an implementation of a random number generator. - Using rng As New RNGCryptoServiceProvider() + + Using rng As RandomNumberGenerator = RandomNumberGenerator.Create() ' The array is now filled with cryptographically strong random bytes. rng.GetBytes(secretkey) diff --git a/snippets/visualbasic/VS_Snippets_CLR/HMACSHA384/vb/hmacsha384.vb b/snippets/visualbasic/VS_Snippets_CLR/HMACSHA384/vb/hmacsha384.vb index b0162858527..032f283fb19 100644 --- a/snippets/visualbasic/VS_Snippets_CLR/HMACSHA384/vb/hmacsha384.vb +++ b/snippets/visualbasic/VS_Snippets_CLR/HMACSHA384/vb/hmacsha384.vb @@ -27,8 +27,8 @@ Public Class HMACSHA384example ' Create a random key using a random number generator. This would be the ' secret key shared by sender and receiver. Dim secretkey() As Byte = New [Byte](63) {} - 'RNGCryptoServiceProvider is an implementation of a random number generator. - Using rng As New RNGCryptoServiceProvider() + + Using rng As RandomNumberGenerator = RandomNumberGenerator.Create() ' The array is now filled with cryptographically strong random bytes. rng.GetBytes(secretkey) diff --git a/snippets/visualbasic/VS_Snippets_CLR/HMACSHA512/vb/hmacsha512.vb b/snippets/visualbasic/VS_Snippets_CLR/HMACSHA512/vb/hmacsha512.vb index c91328f5fed..ebc9962d69f 100644 --- a/snippets/visualbasic/VS_Snippets_CLR/HMACSHA512/vb/hmacsha512.vb +++ b/snippets/visualbasic/VS_Snippets_CLR/HMACSHA512/vb/hmacsha512.vb @@ -27,8 +27,8 @@ Public Class HMACSHA5126example ' Create a random key using a random number generator. This would be the ' secret key shared by sender and receiver. Dim secretkey() As Byte = New [Byte](63) {} - 'RNGCryptoServiceProvider is an implementation of a random number generator. - Using rng As New RNGCryptoServiceProvider() + + Using rng As RandomNumberGenerator = RandomNumberGenerator.Create() ' The array is now filled with cryptographically strong random bytes. rng.GetBytes(secretkey) diff --git a/snippets/visualbasic/VS_Snippets_CLR/MAC3DES/VB/program.vb b/snippets/visualbasic/VS_Snippets_CLR/MAC3DES/VB/program.vb index 8daea1441d2..717c2a2367c 100644 --- a/snippets/visualbasic/VS_Snippets_CLR/MAC3DES/VB/program.vb +++ b/snippets/visualbasic/VS_Snippets_CLR/MAC3DES/VB/program.vb @@ -27,8 +27,8 @@ Public Class MACTripleDESexample ' Create a random key using a random number generator. This would be the ' secret key shared by sender and receiver. Dim secretkey() As Byte = New [Byte](23) {} - 'RNGCryptoServiceProvider is an implementation of a random number generator. - Using rng As New RNGCryptoServiceProvider() + + Using rng As RandomNumberGenerator = RandomNumberGenerator.Create() ' The array is now filled with cryptographically strong random bytes. rng.GetBytes(secretkey) diff --git a/snippets/visualbasic/VS_Snippets_CLR/rfc28981/vb/rfc28981.vb b/snippets/visualbasic/VS_Snippets_CLR/rfc28981/vb/rfc28981.vb index 653476ec08d..999cab698cb 100644 --- a/snippets/visualbasic/VS_Snippets_CLR/rfc28981/vb/rfc28981.vb +++ b/snippets/visualbasic/VS_Snippets_CLR/rfc28981/vb/rfc28981.vb @@ -22,8 +22,8 @@ Public Class rfc2898test Dim pwd1 As String = passwordargs(0) Dim salt1(8) As Byte - Using rngCsp As New RNGCryptoServiceProvider() - rngCsp.GetBytes(salt1) + Using rng As RandomNumberGenerator = RandomNumberGenerator.Create() + rng.GetBytes(salt1) End Using 'data1 can be a string or contents of a file. Dim data1 As String = "Some test data" diff --git a/snippets/visualbasic/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetBytes Example/VB/source.vb b/snippets/visualbasic/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetBytes Example/VB/source.vb index 3789927d87a..2ac319faffc 100644 --- a/snippets/visualbasic/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetBytes Example/VB/source.vb +++ b/snippets/visualbasic/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetBytes Example/VB/source.vb @@ -9,9 +9,9 @@ Public Class Form1 ' Dim random() As Byte = New Byte(100) {} - 'RNGCryptoServiceProvider is an implementation of an RNG - Dim rng As New RNGCryptoServiceProvider() - rng.GetBytes(random) ' bytes in random are now random + Using rng As RandomNumberGenerator = RandomNumberGenerator.Create() + rng.GetBytes(random) ' bytes in random are now random + End Using ' End Sub End Class diff --git a/snippets/visualbasic/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetNonZeroBytes Example/VB/source.vb b/snippets/visualbasic/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetNonZeroBytes Example/VB/source.vb index 975a1d7a382..328fdee0044 100644 --- a/snippets/visualbasic/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetNonZeroBytes Example/VB/source.vb +++ b/snippets/visualbasic/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetNonZeroBytes Example/VB/source.vb @@ -8,9 +8,10 @@ Public Class Form1 Public Sub Method() ' Dim random() As Byte = New Byte(100) {} - 'RNGCryptoServiceProvider is an implementation of an RNG - Dim rng As New RNGCryptoServiceProvider() - rng.GetNonZeroBytes(random) ' bytes in random are now random and none are zero + + Using rng As RandomNumberGenerator = RandomNumberGenerator.Create() + rng.GetNonZeroBytes(random) ' bytes in random are now random and none are zero + End Using ' End Sub End Class diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.RSAOAEPKeyExchangeDeformatter/VB/rsaencoder.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.RSAOAEPKeyExchangeDeformatter/VB/rsaencoder.vb index 0ef5c64e438..52f9cfad7c3 100644 --- a/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.RSAOAEPKeyExchangeDeformatter/VB/rsaencoder.vb +++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.RSAOAEPKeyExchangeDeformatter/VB/rsaencoder.vb @@ -116,9 +116,9 @@ Public Class Form1 rsaFormatter.SetKey(key) ' - ' Create a random number using the RNGCryptoServiceProvider provider. + ' Create a random number using the RandomNumberGenerator. ' - Dim ring As New RNGCryptoServiceProvider + Dim ring As RandomNumberGenerator = RandomNumberGenerator.Create() rsaFormatter.Rng = ring '