Skip to content

Commit 0ab1ab3

Browse files
authored
Replace MD5 and SHA1 (#4542)
1 parent 047317f commit 0ab1ab3

File tree

57 files changed

+168
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+168
-101
lines changed

samples/snippets/cpp/VS_Snippets_CLR/AssemblyName_CodeBase/CPP/assemblyname_codebase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ int main()
7171
// Set the culture information of the assembly to 'English-American'.
7272
myAssemblyName->CultureInfo = gcnew CultureInfo( "en-US" );
7373

74-
// Set the hash algoritm to 'SHA1'.
75-
myAssemblyName->HashAlgorithm = AssemblyHashAlgorithm::SHA1;
74+
// Set the hash algorithm to 'SHA256'.
75+
myAssemblyName->HashAlgorithm = AssemblyHashAlgorithm::SHA256;
7676
myAssemblyName->Name = "MyAssembly";
7777
myAssemblyName->Version = gcnew Version( "1.0.0.2001" );
7878
MakeAssembly( myAssemblyName, "MyAssembly.exe" );

samples/snippets/cpp/VS_Snippets_CLR/AssemblyName_KeyPair/CPP/assemblyname_keypair.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ int main()
7878
// Set the culture information of the assembly to 'English-American'.
7979
myAssemblyName->CultureInfo = gcnew CultureInfo( "en-US" );
8080

81-
// Set the hash algoritm to 'SHA1'.
82-
myAssemblyName->HashAlgorithm = AssemblyHashAlgorithm::SHA1;
81+
// Set the hash algorithm to 'SHA256'.
82+
myAssemblyName->HashAlgorithm = AssemblyHashAlgorithm::SHA256;
8383
myAssemblyName->VersionCompatibility = AssemblyVersionCompatibility::SameProcess;
8484
myAssemblyName->Flags = AssemblyNameFlags::PublicKey;
8585

samples/snippets/cpp/VS_Snippets_CLR/AssemblyName_SetPublicKey/CPP/assemblyname_setpublickey.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ int main()
7474
// Set the culture information of the assembly to 'English-American'.
7575
myAssemblyName->CultureInfo = gcnew CultureInfo( "en-US" );
7676

77-
// Set the hash algoritm to 'SHA1'.
78-
myAssemblyName->HashAlgorithm = AssemblyHashAlgorithm::SHA1;
77+
// Set the hash algorithm to 'SHA256'.
78+
myAssemblyName->HashAlgorithm = AssemblyHashAlgorithm::SHA256;
7979
myAssemblyName->VersionCompatibility = AssemblyVersionCompatibility::SameProcess;
8080
myAssemblyName->Flags = AssemblyNameFlags::PublicKey;
8181

samples/snippets/cpp/VS_Snippets_CLR/Cryptography.PasswordDerivedbytes/cpp/sample.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ int main(array<String^>^ args)
7474
// <Snippet2>
7575
// Create the key and set it to the Key property
7676
// of the TripleDESCryptoServiceProvider object.
77+
// This example uses the SHA1 algorithm.
78+
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
7779
cryptoDESProvider->Key = passwordDeriveBytes->CryptDeriveKey
7880
("TripleDES", "SHA1", 192, cryptoDESProvider->IV);
7981
//</Snippet2>

samples/snippets/cpp/VS_Snippets_CLR/Cryptography.RSACSP.SignData1/CPP/example.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ array<Byte>^ HashAndSignBytes( array<Byte>^DataToSign, RSAParameters Key, int In
1313
RSACryptoServiceProvider^ RSAalg = gcnew RSACryptoServiceProvider;
1414
RSAalg->ImportParameters( Key );
1515

16-
// Hash and sign the data. Pass a new instance of SHA1CryptoServiceProvider
17-
// to specify the use of SHA1 for hashing.
18-
return RSAalg->SignData( DataToSign, Index, Length, gcnew SHA1CryptoServiceProvider );
16+
// Hash and sign the data. Pass a new instance of SHA256
17+
// to specify the hashing algorithm.
18+
return RSAalg->SignData( DataToSign, Index, Length, SHA256::Create() );
1919
}
2020
catch ( CryptographicException^ e )
2121
{
@@ -35,9 +35,9 @@ bool VerifySignedHash( array<Byte>^DataToVerify, array<Byte>^SignedData, RSAPara
3535
RSACryptoServiceProvider^ RSAalg = gcnew RSACryptoServiceProvider;
3636
RSAalg->ImportParameters( Key );
3737

38-
// Verify the data using the signature. Pass a new instance of SHA1CryptoServiceProvider
39-
// to specify the use of SHA1 for hashing.
40-
return RSAalg->VerifyData( DataToVerify, gcnew SHA1CryptoServiceProvider, SignedData );
38+
// Verify the data using the signature. Pass a new instance of SHA256
39+
// to specify the hashing algorithm.
40+
return RSAalg->VerifyData( DataToVerify, SHA256::Create(), SignedData );
4141
}
4242
catch ( CryptographicException^ e )
4343
{

samples/snippets/cpp/VS_Snippets_CLR/Cryptography.RSACSP.SignData2/CPP/example.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ array<Byte>^ HashAndSignBytes( array<Byte>^DataToSign, RSAParameters Key )
1313
RSACryptoServiceProvider^ RSAalg = gcnew RSACryptoServiceProvider;
1414
RSAalg->ImportParameters( Key );
1515

16-
// Hash and sign the data. Pass a new instance of SHA1CryptoServiceProvider
17-
// to specify the use of SHA1 for hashing.
18-
return RSAalg->SignData( DataToSign, gcnew SHA1CryptoServiceProvider );
16+
// Hash and sign the data. Pass a new instance of SHA256
17+
// to specify the hashing algorithm.
18+
return RSAalg->SignData( DataToSign, SHA256::Create() );
1919
}
2020
catch ( CryptographicException^ e )
2121
{
@@ -35,9 +35,9 @@ bool VerifySignedHash( array<Byte>^DataToVerify, array<Byte>^SignedData, RSAPara
3535
RSACryptoServiceProvider^ RSAalg = gcnew RSACryptoServiceProvider;
3636
RSAalg->ImportParameters( Key );
3737

38-
// Verify the data using the signature. Pass a new instance of SHA1CryptoServiceProvider
39-
// to specify the use of SHA1 for hashing.
40-
return RSAalg->VerifyData( DataToVerify, gcnew SHA1CryptoServiceProvider, SignedData );
38+
// Verify the data using the signature. Pass a new instance of SHA256
39+
// to specify the hashing algorithm.
40+
return RSAalg->VerifyData( DataToVerify, SHA256::Create(), SignedData );
4141
}
4242
catch ( CryptographicException^ e )
4343
{

samples/snippets/cpp/VS_Snippets_CLR/Cryptography.RSACSP.SignData3/CPP/example.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ array<Byte>^ HashAndSignBytes( Stream^ DataStream, RSAParameters Key )
2020
RSACryptoServiceProvider^ RSAalg = gcnew RSACryptoServiceProvider;
2121
RSAalg->ImportParameters( Key );
2222

23-
// Hash and sign the data. Pass a new instance of SHA1CryptoServiceProvider
24-
// to specify the use of SHA1 for hashing.
25-
return RSAalg->SignData( DataStream, gcnew SHA1CryptoServiceProvider );
23+
// Hash and sign the data. Pass a new instance of SHA256
24+
// to specify the hashing algorithm.
25+
return RSAalg->SignData( DataStream, SHA256::Create() );
2626
}
2727
catch ( CryptographicException^ e )
2828
{
@@ -42,9 +42,9 @@ bool VerifySignedHash( array<Byte>^DataToVerify, array<Byte>^SignedData, RSAPara
4242
RSACryptoServiceProvider^ RSAalg = gcnew RSACryptoServiceProvider;
4343
RSAalg->ImportParameters( Key );
4444

45-
// Verify the data using the signature. Pass a new instance of SHA1CryptoServiceProvider
46-
// to specify the use of SHA1 for hashing.
47-
return RSAalg->VerifyData( DataToVerify, gcnew SHA1CryptoServiceProvider, SignedData );
45+
// Verify the data using the signature. Pass a new instance of SHA256
46+
// to specify the hashing algorithm.
47+
return RSAalg->VerifyData( DataToVerify, SHA256(), SignedData );
4848
}
4949
catch ( CryptographicException^ e )
5050
{

samples/snippets/cpp/VS_Snippets_CLR/Cryptography.SmartCardCSP/CPP/Cryptography.SmartCardCSP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ int main()
2727
Console::WriteLine( L"Data : {0}", BitConverter::ToString( data ) );
2828

2929
// Sign the data using the Smart Card CryptoGraphic Provider.
30-
array<Byte>^sig = rsa->SignData( data, L"SHA1" );
30+
array<Byte>^sig = rsa->SignData( data, L"SHA256" );
3131
Console::WriteLine( L"Signature : {0}", BitConverter::ToString( sig ) );
3232

3333
// Verify the data using the Smart Card CryptoGraphic Provider.
34-
bool verified = rsa->VerifyData( data, L"SHA1", sig );
34+
bool verified = rsa->VerifyData( data, L"SHA256", sig );
3535
Console::WriteLine( L"Verified : {0}", verified );
3636
}
3737

samples/snippets/cpp/VS_Snippets_CLR_Classic/classic HashAlgorithm Example/CPP/source.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public ref class Form1: public Form
1515
void Method()
1616
{
1717
// <Snippet1>
18-
HashAlgorithm^ sha = gcnew SHA1CryptoServiceProvider;
18+
HashAlgorithm^ sha = SHA256::Create();
1919
array<Byte>^ result = sha->ComputeHash( dataArray );
2020
// </Snippet1>
2121
}

samples/snippets/cpp/VS_Snippets_CLR_System/System.Security.Cryptography.RSACryptoServiceProvider ManualHash Example/CPP/class1.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22

33
//<snippet1>
4+
// This example uses the SHA1 algorithm.
5+
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
46
#using <System.dll>
57

68
using namespace System;

0 commit comments

Comments
 (0)