Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//<SNIPPET1>

Check failure on line 1 in snippets/cpp/VS_Snippets_CLR/Cryptography.PasswordDerivedbytes/cpp/sample.cpp

View workflow job for this annotation

GitHub Actions / snippets-build

ERROR: Project missing. A project (and optionally a solution file) must be in this directory or one of the parent directories to validate and build this code.
using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Text;
Expand All @@ -18,12 +18,12 @@
randomBytes = gcnew array <Byte>(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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

Check failure on line 1 in snippets/cpp/VS_Snippets_CLR/HMACRIPEMD160/CPP/hmacripemd160.cpp

View workflow job for this annotation

GitHub Actions / snippets-build

ERROR: Project missing. A project (and optionally a solution file) must be in this directory or one of the parent directories to validate and build this code.
//<SNIPPET1>
using namespace System;
using namespace System::IO;
Expand Down Expand Up @@ -111,8 +111,7 @@
// secret key shared by sender and receiver.
array<Byte>^secretkey = gcnew array<Byte>(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 );
Expand Down
2 changes: 2 additions & 0 deletions snippets/cpp/VS_Snippets_CLR/HMACRIPEMD160/CPP/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
System.Security.Cryptography.HMACRIPEMD160.exe: hmacripemd160.cpp
cl /FeSystem.Security.Cryptography.HMACRIPEMD160.exe /clr:pure hmacripemd160.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

Check failure on line 1 in snippets/cpp/VS_Snippets_CLR/HMACSHA256/CPP/hmacsha256.cpp

View workflow job for this annotation

GitHub Actions / snippets-build

ERROR: Project missing. A project (and optionally a solution file) must be in this directory or one of the parent directories to validate and build this code.
//<SNIPPET1>
using namespace System;
using namespace System::IO;
Expand Down Expand Up @@ -111,8 +111,7 @@
// secret key shared by sender and receiver.
array<Byte>^secretkey = gcnew array<Byte>(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 );
Expand Down
2 changes: 2 additions & 0 deletions snippets/cpp/VS_Snippets_CLR/HMACSHA256/CPP/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
System.Security.Cryptography.HMACSHA256.exe: hmacsha256.cpp
cl /FeSystem.Security.Cryptography.HMACSHA256.exe /clr:pure hmacsha256.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

Check failure on line 1 in snippets/cpp/VS_Snippets_CLR/HMACSHA384/CPP/hmacsha384.cpp

View workflow job for this annotation

GitHub Actions / snippets-build

ERROR: Project missing. A project (and optionally a solution file) must be in this directory or one of the parent directories to validate and build this code.
//<SNIPPET1>
using namespace System;
using namespace System::IO;
Expand Down Expand Up @@ -111,8 +111,7 @@
// secret key shared by sender and receiver.
array<Byte>^secretkey = gcnew array<Byte>(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 );
Expand Down
2 changes: 2 additions & 0 deletions snippets/cpp/VS_Snippets_CLR/HMACSHA384/CPP/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
System.Security.Cryptography.HMACSHA384.exe: hmacsha384.cpp
cl /FeSystem.Security.Cryptography.HMACSHA384.exe /clr:pure hmacsha384.cpp
5 changes: 2 additions & 3 deletions snippets/cpp/VS_Snippets_CLR/HMACSHA512/CPP/hmacsha512.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

Check failure on line 1 in snippets/cpp/VS_Snippets_CLR/HMACSHA512/CPP/hmacsha512.cpp

View workflow job for this annotation

GitHub Actions / snippets-build

ERROR: Project missing. A project (and optionally a solution file) must be in this directory or one of the parent directories to validate and build this code.
//<SNIPPET1>
using namespace System;
using namespace System::IO;
Expand Down Expand Up @@ -110,9 +110,8 @@
// Create a random key using a random number generator. This would be the
// secret key shared by sender and receiver.
array<Byte>^secretkey = gcnew array<Byte>(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 );
Expand Down
2 changes: 2 additions & 0 deletions snippets/cpp/VS_Snippets_CLR/HMACSHA512/CPP/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
System.Security.Cryptography.HMACSHA512.exe: hmacsha512.cpp
cl /FeSystem.Security.Cryptography.HMACSHA512.exe /clr:pure hmacsha512.cpp
4 changes: 2 additions & 2 deletions snippets/cpp/VS_Snippets_CLR/rfc28981/CPP/rfc28981.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

Check failure on line 1 in snippets/cpp/VS_Snippets_CLR/rfc28981/CPP/rfc28981.cpp

View workflow job for this annotation

GitHub Actions / snippets-build

ERROR: Project missing. A project (and optionally a solution file) must be in this directory or one of the parent directories to validate and build this code.
//<SNIPPET1>
using namespace System;
using namespace System::IO;
Expand Down Expand Up @@ -27,8 +27,8 @@
String^ pwd1 = passwordargs[ 1 ];

array<Byte>^salt1 = gcnew array<Byte>(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";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#using <System.dll>

Check failure on line 1 in snippets/cpp/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetBytes Example/CPP/source.cpp

View workflow job for this annotation

GitHub Actions / snippets-build

ERROR: Project missing. A project (and optionally a solution file) must be in this directory or one of the parent directories to validate and build this code.
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
Expand All @@ -16,8 +16,7 @@
// <Snippet1>
array<Byte>^ random = gcnew array<Byte>(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.
// </Snippet1>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#using <System.dll>

Check failure on line 1 in snippets/cpp/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetNonZeroBytes Example/CPP/source.cpp

View workflow job for this annotation

GitHub Actions / snippets-build

ERROR: Project missing. A project (and optionally a solution file) must be in this directory or one of the parent directories to validate and build this code.
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
Expand All @@ -15,8 +15,7 @@
{
// <Snippet1>
array<Byte>^ random = gcnew array<Byte>(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.
// </Snippet1>
}
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adegeo Why does Snippets 5000 care about this file given that it's configured to ignore .cpp files? See

ExtensionsCodeTriggers: .cs;.vb;.fs;.xaml;.razor;.cshtml;.vbhtml;.sln;.csproj;.fsproj;.vbproj;.proj
.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This sample demonstrates how to encode and decode a string using

Check failure on line 1 in snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.RSAOAEPKeyExchangeDeformatter/CPP/rsaencoder.cpp

View workflow job for this annotation

GitHub Actions / snippets-build

ERROR: Project missing. A project (and optionally a solution file) must be in this directory or one of the parent directories to validate and build this code.
// the RSAOAEPKeyExchangeFormatter and RSAOAEPKeyExchangeDeformatter classes.
//<Snippet2>
using namespace System;
Expand Down Expand Up @@ -122,7 +122,7 @@

// Create a random number using the RNGCryptoServiceProvider provider.
//<Snippet6>
RNGCryptoServiceProvider^ ring = gcnew RNGCryptoServiceProvider;
RandomNumberGenerator^ ring = RandomNumberGenerator::Create();
rsaFormatter->Rng = ring;
//</Snippet6>

Expand Down Expand Up @@ -190,7 +190,7 @@
//
// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ private void ConstructFormatter()
rsaFormatter.SetKey(key);
//</Snippet5>

// Create a random number using the RNGCryptoServiceProvider provider.
// Create a random number using the RandomNumberGenerator
//<Snippet6>
RNGCryptoServiceProvider ring = new RNGCryptoServiceProvider();
RandomNumberGenerator ring = RandomNumberGenerator.Create();
rsaFormatter.Rng = ring;
//</Snippet6>

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
{
// <Snippet1>
byte[] random = new Byte[100];
// <Snippet1>
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.
// </Snippet1>
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
{
rng.GetBytes(random); // The array is now filled with cryptographically strong random bytes.
}
// </Snippet1>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ public class Form1: Form
public void Method()
{
// <Snippet1>
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.
}
// </Snippet1>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions snippets/csharp/VS_Snippets_CFX/samlattribute/cs/Project.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net4.8</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Reference Include="System.Configuration" />
<Reference Include="System.IdentityModel" />
<Reference Include="System.ServiceModel" />
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions snippets/csharp/VS_Snippets_CFX/samlattribute/cs/makefile

This file was deleted.

Loading