This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make SHA256 algorithm creation FIPS compliant.
- Loading branch information
1 parent
a5f3a64
commit 6c69cb8
Showing
3 changed files
with
27 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/CryptographyAlgorithms.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Security.Cryptography; | ||
|
||
namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal | ||
{ | ||
public static class CryptographyAlgorithms | ||
{ | ||
public static SHA256 CreateSHA256() | ||
{ | ||
try | ||
{ | ||
return SHA256.Create(); | ||
} | ||
// SHA256.Create is documented to throw this exception on FIPS compliant machines. | ||
// See: https://msdn.microsoft.com/en-us/library/z08hz7ad%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 | ||
catch (System.Reflection.TargetInvocationException) | ||
{ | ||
// Fallback to a FIPS compliant SHA256 algorithm. | ||
return new SHA256CryptoServiceProvider(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters