Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
first batch
  • Loading branch information
tdykstra committed Jul 17, 2020
commit fb4818449e85c8e97ea2f66b7c8ae85096db0b8d
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 algoritm 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 @@ -70,7 +70,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.
// to specify the hashing algorithm.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
return RSAalg.SignData(DataToSign,Index,Length, new SHA1CryptoServiceProvider());
}
catch(CryptographicException e)
Expand All @@ -92,7 +94,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.
// to specify the hashing algorithm.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
return RSAalg.VerifyData(DataToVerify, new SHA1CryptoServiceProvider(), SignedData);
}
catch(CryptographicException e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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.
// to specify the hashing algorithm.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
return RSAalg.SignData(DataToSign, new SHA1CryptoServiceProvider());
}
catch(CryptographicException e)
Expand All @@ -80,7 +82,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.
// to specify the hashing algorithm.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
return RSAalg.VerifyData(DataToVerify, new SHA1CryptoServiceProvider(), SignedData);
}
catch(CryptographicException e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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.
// to specify the hashing algorithm.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
return RSAalg.SignData(DataStream, new SHA1CryptoServiceProvider());
}
catch(CryptographicException e)
Expand All @@ -97,7 +99,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.
// to specify the hashing algorithm.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
return RSAalg.VerifyData(DataToVerify, new SHA1CryptoServiceProvider(), 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
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 @@ -18,7 +18,7 @@ Namespace CreateSts
Sub AddSigningCredentials(ByVal assertion As SamlAssertion, _
ByVal signingKey As SecurityKey)
Dim sc As New SigningCredentials(signingKey, _
SecurityAlgorithms.RsaSha1Signature, SecurityAlgorithms.Sha1Digest)
SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest)
assertion.SigningCredentials = sc

End Sub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,8 @@ Namespace Microsoft.ServiceModel.Samples.Federation
End Class


' This example uses the SHA1 algorithm.
' Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
Public Class ComputedKeyAlgorithms
Public Const PSHA1 As String = "http://schemas.xmlsoap.org/ws/2005/02/trust/CK/PSHA1"
End Class
Expand Down Expand Up @@ -1027,6 +1029,8 @@ Namespace Microsoft.ServiceModel.Samples.Federation
'/ <param name="keySize">Size of required key, in bits.</param>
'/ <returns>Array of bytes that contains key material.</returns>
Public Shared Function ComputeCombinedKey(ByVal requestorEntropy() As Byte, ByVal issuerEntropy() As Byte, ByVal keySize As Integer) As Byte()
' This example uses the SHA1 algorithm.
' Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
Dim kha As KeyedHashAlgorithm = New HMACSHA1(requestorEntropy, True)

Dim key(keySize / 8 - 1) As Byte ' Final key
Expand Down Expand Up @@ -1132,7 +1136,8 @@ Namespace Microsoft.ServiceModel.Samples.Federation
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 @@ -1258,6 +1263,8 @@ Namespace Microsoft.ServiceModel.Samples.Federation
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.
Dim signingCredentials As New SigningCredentials(issuerToken.SecurityKeys(0), SecurityAlgorithms.RsaSha1Signature, SecurityAlgorithms.Sha1Digest, issuerKeyIdentifier)

' Create a SamlAssertion from the list of SamlStatements previously created and the passed in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ Public Class AssemblyName_CodeBase
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 algoritm to 'SHA256'.
myAssemblyName.HashAlgorithm = AssemblyHashAlgorithm.SHA256
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 @@ -66,8 +66,8 @@ Public Class AssemblyName_CodeBase
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 algoritm 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 @@ -57,8 +57,8 @@ Public Class AssemblyName_CodeBase
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 algoritm 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 @@ -30,6 +30,8 @@ Module PasswordDerivedBytesExample

' 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 @@ -62,7 +62,9 @@ Module RSACSPExample
RSAalg.ImportParameters(Key)

' Hash and sign the data. Pass a new instance of SHA1CryptoServiceProvider
' to specify the use of SHA1 for hashing.
' to specify the hashing algorithm.
' This example uses the SHA1 algorithm.
' Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
Return RSAalg.SignData(DataToSign, Index, Length, New SHA1CryptoServiceProvider)
Catch e As CryptographicException
Console.WriteLine(e.Message)
Expand All @@ -81,7 +83,9 @@ Module RSACSPExample
RSAalg.ImportParameters(Key)

' Verify the data using the signature. Pass a new instance of SHA1CryptoServiceProvider
' to specify the use of SHA1 for hashing.
' to specify the hashing algorithm.
' This example uses the SHA1 algorithm.
' Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
Return RSAalg.VerifyData(DataToVerify, New SHA1CryptoServiceProvider, SignedData)

Catch e As CryptographicException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ Module RSACSPExample
RSAalg.ImportParameters(Key)

' Hash and sign the data. Pass a new instance of SHA1CryptoServiceProvider
' to specify the use of SHA1 for hashing.
' to specify the hashing algorithm.
' This example uses the SHA1 algorithm.
' Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
Return RSAalg.SignData(DataToSign, New SHA1CryptoServiceProvider)
Catch e As CryptographicException
Console.WriteLine(e.Message)
Expand All @@ -69,7 +71,9 @@ Module RSACSPExample
RSAalg.ImportParameters(Key)

' Verify the data using the signature. Pass a new instance of SHA1CryptoServiceProvider
' to specify the use of SHA1 for hashing.
' to specify the hashing algorithm.
' This example uses the SHA1 algorithm.
' Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
Return RSAalg.VerifyData(DataToVerify, New SHA1CryptoServiceProvider, SignedData)

Catch e As CryptographicException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ Module RSACSPExample
RSAalg.ImportParameters(Key)

' Hash and sign the data. Pass a new instance of SHA1CryptoServiceProvider
' to specify the use of SHA1 for hashing.
' to specify the hashing algorithm.
' This example uses the SHA1 algorithm.
' Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
Return RSAalg.SignData(DataStream, New SHA1CryptoServiceProvider)
Catch e As CryptographicException
Console.WriteLine(e.Message)
Expand All @@ -93,7 +95,9 @@ Module RSACSPExample
RSAalg.ImportParameters(Key)

' Verify the data using the signature. Pass a new instance of SHA1CryptoServiceProvider
' to specify the use of SHA1 for hashing.
' to specify the hashing algorithm.
' This example uses the SHA1 algorithm.
' Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
Return RSAalg.VerifyData(DataToVerify, New SHA1CryptoServiceProvider, SignedData)

Catch e As CryptographicException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Public Class Form1

Protected Sub Method()
' <Snippet1>
Dim sha As New SHA1CryptoServiceProvider()
Dim sha As SHA256 = SHA256.Create()
Dim result As Byte() = sha.ComputeHash(dataArray)
' </Snippet1>
End Sub
Expand Down
Loading