Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 2f46113

Browse files
author
N. Taylor Mullen
committed
Merge branch 'rel/1.0.1' into dev
2 parents 516d916 + edb5baf commit 2f46113

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

src/Microsoft.AspNetCore.Mvc.TagHelpers/Cache/CacheTagKey.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Security.Cryptography;
77
using System.Text;
88
using Microsoft.AspNetCore.Http;
9+
using Microsoft.AspNetCore.Mvc.TagHelpers.Internal;
910
using Microsoft.AspNetCore.Razor.TagHelpers;
1011
using Microsoft.AspNetCore.Routing;
1112
using Microsoft.Extensions.Internal;
@@ -151,10 +152,10 @@ public string GenerateHashedKey()
151152
// The key is typically too long to be useful, so we use a cryptographic hash
152153
// as the actual key (better randomization and key distribution, so small vary
153154
// values will generate dramatically different keys).
154-
using (var sha = SHA256.Create())
155+
using (var sha256 = CryptographyAlgorithms.CreateSHA256())
155156
{
156157
var contentBytes = Encoding.UTF8.GetBytes(key);
157-
var hashedBytes = sha.ComputeHash(contentBytes);
158+
var hashedBytes = sha256.ComputeHash(contentBytes);
158159
return Convert.ToBase64String(hashedBytes);
159160
}
160161
}
@@ -183,14 +184,14 @@ public bool Equals(CacheTagKey other)
183184
AreSame(_headers, other._headers) &&
184185
AreSame(_queries, other._queries) &&
185186
AreSame(_routeValues, other._routeValues) &&
186-
_varyByUser == other._varyByUser &&
187+
_varyByUser == other._varyByUser &&
187188
(!_varyByUser || string.Equals(other._username, _username, StringComparison.Ordinal));
188189
}
189190

190191
/// <inheritdoc />
191192
public override int GetHashCode()
192193
{
193-
// The hashcode is intentionally not using the computed
194+
// The hashcode is intentionally not using the computed
194195
// stringified key in order to prevent string allocations
195196
// in the common case where it's not explicitly required.
196197

@@ -219,7 +220,7 @@ public override int GetHashCode()
219220

220221
return _hashcode.Value;
221222
}
222-
223+
223224
private static IList<KeyValuePair<string, string>> ExtractCollection<TSourceCollection>(string keys, TSourceCollection collection, Func<TSourceCollection, string, string> accessor)
224225
{
225226
if (string.IsNullOrEmpty(keys))
@@ -244,7 +245,7 @@ private static IList<KeyValuePair<string, string>> ExtractCollection<TSourceColl
244245

245246
return result;
246247
}
247-
248+
248249
private static void AddStringCollection(
249250
StringBuilder builder,
250251
string collectionName,
@@ -275,7 +276,7 @@ private static void AddStringCollection(
275276
.Append(CacheKeyTokenSeparator)
276277
.Append(item.Value);
277278
}
278-
279+
279280
builder.Append(")");
280281
}
281282

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Security.Cryptography;
5+
6+
namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal
7+
{
8+
public static class CryptographyAlgorithms
9+
{
10+
#if NETSTANDARD1_6
11+
public static SHA256 CreateSHA256()
12+
{
13+
var sha256 = SHA256.Create();
14+
15+
return sha256;
16+
}
17+
#else
18+
public static SHA256 CreateSHA256()
19+
{
20+
SHA256 sha256;
21+
22+
try
23+
{
24+
sha256 = SHA256.Create();
25+
}
26+
// SHA256.Create is documented to throw this exception on FIPS compliant machines.
27+
// See: https://msdn.microsoft.com/en-us/library/z08hz7ad%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
28+
catch (System.Reflection.TargetInvocationException)
29+
{
30+
// Fallback to a FIPS compliant SHA256 algorithm.
31+
sha256 = new SHA256CryptoServiceProvider();
32+
}
33+
34+
return sha256;
35+
}
36+
#endif
37+
}
38+
}

src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/FileVersionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public string AddFileVersionToPath(string path)
111111

112112
private static string GetHashForFile(IFileInfo fileInfo)
113113
{
114-
using (var sha256 = SHA256.Create())
114+
using (var sha256 = CryptographyAlgorithms.CreateSHA256())
115115
{
116116
using (var readStream = fileInfo.CreateReadStream())
117117
{

0 commit comments

Comments
 (0)