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
Expand Up @@ -71,8 +71,8 @@ int main()
// Set the culture information of the assembly to 'English-American'.
myAssemblyName->CultureInfo = gcnew CultureInfo( "en-US" );

// Set the hash algoritm to 'SHA1'.
myAssemblyName->HashAlgorithm = AssemblyHashAlgorithm::SHA1;
// Set the hash algorithm to 'SHA256'.
myAssemblyName->HashAlgorithm = AssemblyHashAlgorithm::SHA256;
Copy link
Member

Choose a reason for hiding this comment

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

I don't know that SHA256 actually works here.

myAssemblyName->Name = "MyAssembly";
myAssemblyName->Version = gcnew Version( "1.0.0.2001" );
MakeAssembly( myAssemblyName, "MyAssembly.exe" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ int main()
// Set the culture information of the assembly to 'English-American'.
myAssemblyName->CultureInfo = gcnew CultureInfo( "en-US" );

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ int main()
// Set the culture information of the assembly to 'English-American'.
myAssemblyName->CultureInfo = gcnew CultureInfo( "en-US" );

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ int main(array<String^>^ args)
// <Snippet2>
// Create the key and set it to the Key property
// of the TripleDESCryptoServiceProvider object.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
cryptoDESProvider->Key = passwordDeriveBytes->CryptDeriveKey
("TripleDES", "SHA1", 192, cryptoDESProvider->IV);
//</Snippet2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ array<Byte>^ HashAndSignBytes( array<Byte>^DataToSign, RSAParameters Key, int In
RSACryptoServiceProvider^ RSAalg = gcnew RSACryptoServiceProvider;
RSAalg->ImportParameters( Key );

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

// Verify the data using the signature. Pass a new instance of SHA1CryptoServiceProvider
// to specify the use of SHA1 for hashing.
return RSAalg->VerifyData( DataToVerify, gcnew SHA1CryptoServiceProvider, SignedData );
// Verify the data using the signature. Pass a new instance of SHA256
// to specify the hashing algorithm.
return RSAalg->VerifyData( DataToVerify, SHA256::Create(), SignedData );
}
catch ( CryptographicException^ e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ array<Byte>^ HashAndSignBytes( array<Byte>^DataToSign, RSAParameters Key )
RSACryptoServiceProvider^ RSAalg = gcnew RSACryptoServiceProvider;
RSAalg->ImportParameters( Key );

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

// Verify the data using the signature. Pass a new instance of SHA1CryptoServiceProvider
// to specify the use of SHA1 for hashing.
return RSAalg->VerifyData( DataToVerify, gcnew SHA1CryptoServiceProvider, SignedData );
// Verify the data using the signature. Pass a new instance of SHA256
// to specify the hashing algorithm.
return RSAalg->VerifyData( DataToVerify, SHA256::Create(), SignedData );
}
catch ( CryptographicException^ e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ array<Byte>^ HashAndSignBytes( Stream^ DataStream, RSAParameters Key )
RSACryptoServiceProvider^ RSAalg = gcnew RSACryptoServiceProvider;
RSAalg->ImportParameters( Key );

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

// Verify the data using the signature. Pass a new instance of SHA1CryptoServiceProvider
// to specify the use of SHA1 for hashing.
return RSAalg->VerifyData( DataToVerify, gcnew SHA1CryptoServiceProvider, SignedData );
// Verify the data using the signature. Pass a new instance of SHA256
// to specify the hashing algorithm.
return RSAalg->VerifyData( DataToVerify, SHA256(), SignedData );
}
catch ( CryptographicException^ e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ int main()
Console::WriteLine( L"Data : {0}", BitConverter::ToString( data ) );

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public ref class Form1: public Form
void Method()
{
// <Snippet1>
HashAlgorithm^ sha = gcnew SHA1CryptoServiceProvider;
HashAlgorithm^ sha = SHA256::Create();
array<Byte>^ result = sha->ComputeHash( dataArray );
// </Snippet1>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@


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

using namespace System;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ namespace Contoso

// Retrieves the name of the signature alogrithm.
//<Snippet7>
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.

public:
property String^ SignatureAlgorithm
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ namespace Contoso
String^ hashNameValue;

public:
// Initialize a mask to encrypt using the SHA1 algorithm.
// Initialize a mask to encrypt using the SHA256 algorithm.
MaskGenerator()
{
hashNameValue = "SHA1";
hashNameValue = "SHA256";
}

//</Snippet2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ int main()
{
// <Snippet1>
// Create a secure group name.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
SHA1Managed^ Sha1 = gcnew SHA1Managed;
array<Byte>^updHash = Sha1->ComputeHash( Encoding::UTF8->GetBytes( "usernamepassworddomain" ) );
String^ secureGroupName = Encoding::Default->GetString( updHash );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Test
void AddSigningCredentials(SamlAssertion assertion, SecurityKey signingKey)
{
SigningCredentials sc = new SigningCredentials(signingKey,
SecurityAlgorithms.RsaSha1Signature, SecurityAlgorithms.Sha1Digest);
SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest);
assertion.SigningCredentials = sc;
}
//</snippet1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,8 @@ public class Elements

public class ComputedKeyAlgorithms
{
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
public const string PSHA1 = "http://schemas.xmlsoap.org/ws/2005/02/trust/CK/PSHA1";
}
}
Expand Down Expand Up @@ -1054,6 +1056,8 @@ public bool ComputeKey
/// <returns>Array of bytes that contain key material.</returns>
public static byte[] ComputeCombinedKey(byte[] requestorEntropy, byte[] issuerEntropy, int keySize)
{
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
KeyedHashAlgorithm kha = new HMACSHA1(requestorEntropy, true);

byte[] key = new byte[keySize / 8]; // Final key
Expand Down Expand Up @@ -1164,7 +1168,8 @@ protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
writer.WriteStartElement(Constants.Trust.Elements.RequestedProofToken, Constants.Trust.NamespaceUri);
// Write the wst:ComputeKey start tag.
writer.WriteStartElement(Constants.Trust.Elements.ComputedKey, Constants.Trust.NamespaceUri);
// Write the PSHA1 algorithm value.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
writer.WriteValue(Constants.Trust.ComputedKeyAlgorithms.PSHA1);
writer.WriteEndElement(); // wst:ComputedKey
writer.WriteEndElement(); // wst:RequestedSecurityToken
Expand Down Expand Up @@ -1295,6 +1300,8 @@ public static SamlSecurityToken CreateSamlToken(string stsName,
samlSubjectStatements.Add(samlAttributeStatement);

// Create a SigningCredentials instance from the key associated with the issuerToken.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
SigningCredentials signingCredentials = new SigningCredentials(issuerToken.SecurityKeys[0],
SecurityAlgorithms.RsaSha1Signature,
SecurityAlgorithms.Sha1Digest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public static void Main()
myAssemblyName.CodeBase = Directory.GetCurrentDirectory();
// Set the culture information of the assembly to 'English-American'.
myAssemblyName.CultureInfo = new CultureInfo("en-US");
// Set the hash algoritm to 'SHA1'.
myAssemblyName.HashAlgorithm = AssemblyHashAlgorithm.SHA1;
// Set the hash algorithm to 'SHA256'.
myAssemblyName.HashAlgorithm = AssemblyHashAlgorithm.SHA256;
Copy link
Member

Choose a reason for hiding this comment

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

Another triplet of AssemblyName.HashAlgorithm being updated. It might work, I just know that some parts of this system are effectively limited to MD5 and SHA1... and I don't know if this is one of them or not. (We could, of course, update them, and if we get feedback it doesn't work, then change them back)

myAssemblyName.Name = "MyAssembly";
myAssemblyName.Version = new Version("1.0.0.2001");
MakeAssembly(myAssemblyName, "MyAssembly.exe");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public static void Main()
myAssemblyName.CodeBase = Directory.GetCurrentDirectory();
// Set the culture information of the assembly to 'English-American'.
myAssemblyName.CultureInfo = new CultureInfo("en-US");
// Set the hash algoritm to 'SHA1'.
myAssemblyName.HashAlgorithm = AssemblyHashAlgorithm.SHA1;
// Set the hash algorithm to 'SHA256'.
myAssemblyName.HashAlgorithm = AssemblyHashAlgorithm.SHA256;
myAssemblyName.VersionCompatibility = AssemblyVersionCompatibility.SameProcess;
myAssemblyName.Flags = AssemblyNameFlags.PublicKey;
// Provide this assembly with a strong name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public static void Main()
myAssemblyName.CodeBase = Directory.GetCurrentDirectory();
// Set the culture information of the assembly to 'English-American'.
myAssemblyName.CultureInfo = new CultureInfo("en-US");
// Set the hash algoritm to 'SHA1'.
myAssemblyName.HashAlgorithm = AssemblyHashAlgorithm.SHA1;
// Set the hash algorithm to 'SHA256'.
myAssemblyName.HashAlgorithm = AssemblyHashAlgorithm.SHA256;
myAssemblyName.VersionCompatibility = AssemblyVersionCompatibility.SameProcess;
myAssemblyName.Flags = AssemblyNameFlags.PublicKey;
// Get the whole contents of the 'PublicKey.snk' into a byte array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public static void Main(String[] args)

// Create the key and set it to the Key property
// of the TripleDESCryptoServiceProvider object.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
tdes.Key = pdb.CryptDeriveKey("TripleDES", "SHA1", 192, tdes.IV);

//</Snippet2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public static byte[] HashAndSignBytes(byte[] DataToSign, RSAParameters Key, int

RSAalg.ImportParameters(Key);

// Hash and sign the data. Pass a new instance of SHA1CryptoServiceProvider
// to specify the use of SHA1 for hashing.
return RSAalg.SignData(DataToSign,Index,Length, new SHA1CryptoServiceProvider());
// Hash and sign the data. Pass a new instance of SHA256
// to specify the hashing algorithm.
return RSAalg.SignData(DataToSign,Index,Length, SHA256.Create());
}
catch(CryptographicException e)
{
Expand All @@ -91,9 +91,9 @@ public static bool VerifySignedHash(byte[] DataToVerify, byte[] SignedData, RSAP

RSAalg.ImportParameters(Key);

// Verify the data using the signature. Pass a new instance of SHA1CryptoServiceProvider
// to specify the use of SHA1 for hashing.
return RSAalg.VerifyData(DataToVerify, new SHA1CryptoServiceProvider(), SignedData);
// Verify the data using the signature. Pass a new instance of SHA256
// to specify the hashing algorithm.
return RSAalg.VerifyData(DataToVerify, SHA256.Create(), SignedData);
}
catch(CryptographicException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public static byte[] HashAndSignBytes(byte[] DataToSign, RSAParameters Key)

RSAalg.ImportParameters(Key);

// Hash and sign the data. Pass a new instance of SHA1CryptoServiceProvider
// to specify the use of SHA1 for hashing.
return RSAalg.SignData(DataToSign, new SHA1CryptoServiceProvider());
// Hash and sign the data. Pass a new instance of SHA256
// to specify the hashing algorithm.
return RSAalg.SignData(DataToSign, SHA256.Create());
}
catch(CryptographicException e)
{
Expand All @@ -79,9 +79,9 @@ public static bool VerifySignedHash(byte[] DataToVerify, byte[] SignedData, RSAP

RSAalg.ImportParameters(Key);

// Verify the data using the signature. Pass a new instance of SHA1CryptoServiceProvider
// to specify the use of SHA1 for hashing.
return RSAalg.VerifyData(DataToVerify, new SHA1CryptoServiceProvider(), SignedData);
// Verify the data using the signature. Pass a new instance of SHA256
// to specify the hashing algorithm.
return RSAalg.VerifyData(DataToVerify, SHA256.Create(), SignedData);
}
catch(CryptographicException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public static byte[] HashAndSignBytes(Stream DataStream, RSAParameters Key)

RSAalg.ImportParameters(Key);

// Hash and sign the data. Pass a new instance of SHA1CryptoServiceProvider
// to specify the use of SHA1 for hashing.
return RSAalg.SignData(DataStream, new SHA1CryptoServiceProvider());
// Hash and sign the data. Pass a new instance of SHA256
// to specify the hashing algorithm.
return RSAalg.SignData(DataStream, SHA256.Create());
}
catch(CryptographicException e)
{
Expand All @@ -96,9 +96,9 @@ public static bool VerifySignedHash(byte[] DataToVerify, byte[] SignedData, RSAP

RSAalg.ImportParameters(Key);

// Verify the data using the signature. Pass a new instance of SHA1CryptoServiceProvider
// to specify the use of SHA1 for hashing.
return RSAalg.VerifyData(DataToVerify, new SHA1CryptoServiceProvider(), SignedData);
// Verify the data using the signature. Pass a new instance of SHA256
// to specify the hashing algorithm.
return RSAalg.VerifyData(DataToVerify, SHA256.Create(), SignedData);
}
catch(CryptographicException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ static void Main(string[] args)
Console.WriteLine("Data : " + BitConverter.ToString(data));

// Sign the data using the Smart Card CryptoGraphic Provider.
byte[] sig = rsa.SignData(data, "SHA1");
byte[] sig = rsa.SignData(data, "SHA256");

Console.WriteLine("Signature : " + BitConverter.ToString(sig));

// Verify the data using the Smart Card CryptoGraphic Provider.
bool verified = rsa.VerifyData(data, "SHA1", sig);
bool verified = rsa.VerifyData(data, "SHA256", sig);

Console.WriteLine("Verified : " + verified);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Form1: Form
protected void Method()
{
// <Snippet1>
HashAlgorithm sha = new SHA1CryptoServiceProvider();
HashAlgorithm sha = SHA256.Create();
byte[] result = sha.ComputeHash(dataArray);
// </Snippet1>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//<Snippet1>
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
using System;
using System.Text;
using System.Security.Cryptography;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ static void DemonstrateCodeDirectives(string providerName, string sourceFileName
File.Delete(sourceFileName);
}

// This example uses the SHA1 and MD5 algorithms.
// Due to collision problems with SHA1 and MD5, Microsoft recommends SHA256 or better.
private static Guid HashMD5 = new Guid(0x406ea660, 0x64cf, 0x4c82, 0xb6, 0xf0, 0x42, 0xd4, 0x81, 0x72, 0xa7, 0x99);
private static Guid HashSHA1 = new Guid(0xff1816ec, 0xaa5e, 0x4d10, 0x87, 0xf7, 0x6f, 0x49, 0x63, 0x83, 0x34, 0x60);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ public override string KeyExchangeAlgorithm

// Retrieves the name of the signature alogrithm.
//<Snippet7>
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
public override string SignatureAlgorithm
{
get {return "http://www.w3.org/2000/09/xmldsig#rsa-sha1";}
Expand Down
Loading