diff --git a/src/Microsoft.AspNetCore.Antiforgery/Internal/AntiforgeryOptionsSetup.cs b/src/Microsoft.AspNetCore.Antiforgery/Internal/AntiforgeryOptionsSetup.cs index 29c3780786..1c5a3fa4b8 100644 --- a/src/Microsoft.AspNetCore.Antiforgery/Internal/AntiforgeryOptionsSetup.cs +++ b/src/Microsoft.AspNetCore.Antiforgery/Internal/AntiforgeryOptionsSetup.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal private static string ComputeCookieName(string applicationId) { - using (var sha256 = CryptographyAlgorithms.CreateSHA256()) + using (var sha256 = SHA256.Create()) { var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(applicationId)); var subHash = hash.Take(8).ToArray(); diff --git a/src/Microsoft.AspNetCore.Antiforgery/Internal/AntiforgerySerializationContext.cs b/src/Microsoft.AspNetCore.Antiforgery/Internal/AntiforgerySerializationContext.cs index 6d697fa0da..5347f6651a 100644 --- a/src/Microsoft.AspNetCore.Antiforgery/Internal/AntiforgerySerializationContext.cs +++ b/src/Microsoft.AspNetCore.Antiforgery/Internal/AntiforgerySerializationContext.cs @@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal { if (_sha256 == null) { - _sha256 = CryptographyAlgorithms.CreateSHA256(); + _sha256 = SHA256.Create(); } return _sha256; diff --git a/src/Microsoft.AspNetCore.Antiforgery/Internal/CryptographyAlgorithms.cs b/src/Microsoft.AspNetCore.Antiforgery/Internal/CryptographyAlgorithms.cs deleted file mode 100644 index c466512fee..0000000000 --- a/src/Microsoft.AspNetCore.Antiforgery/Internal/CryptographyAlgorithms.cs +++ /dev/null @@ -1,40 +0,0 @@ -// 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.Antiforgery.Internal -{ - public static class CryptographyAlgorithms - { -#if NETSTANDARD1_3 - public static SHA256 CreateSHA256() - { - var sha256 = SHA256.Create(); - - return sha256; - } -#elif NET46 - public static SHA256 CreateSHA256() - { - SHA256 sha256; - - try - { - sha256 = 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. - sha256 = new SHA256CryptoServiceProvider(); - } - - return sha256; - } -#else -#error target frameworks need to be updated. -#endif - } -} diff --git a/src/Microsoft.AspNetCore.Antiforgery/Microsoft.AspNetCore.Antiforgery.csproj b/src/Microsoft.AspNetCore.Antiforgery/Microsoft.AspNetCore.Antiforgery.csproj index 0a815abdba..12b72a69c3 100644 --- a/src/Microsoft.AspNetCore.Antiforgery/Microsoft.AspNetCore.Antiforgery.csproj +++ b/src/Microsoft.AspNetCore.Antiforgery/Microsoft.AspNetCore.Antiforgery.csproj @@ -4,7 +4,7 @@ An antiforgery system for ASP.NET Core designed to generate and validate tokens to prevent Cross-Site Request Forgery attacks. - netstandard1.3;net46 + netcoreapp2.0 $(NoWarn);CS1591 true aspnetcore;antiforgery diff --git a/test/Microsoft.AspNetCore.Antiforgery.Test/Internal/DefaultClaimUidExtractorTest.cs b/test/Microsoft.AspNetCore.Antiforgery.Test/Internal/DefaultClaimUidExtractorTest.cs index b03c76e6cc..aa5234c690 100644 --- a/test/Microsoft.AspNetCore.Antiforgery.Test/Internal/DefaultClaimUidExtractorTest.cs +++ b/test/Microsoft.AspNetCore.Antiforgery.Test/Internal/DefaultClaimUidExtractorTest.cs @@ -60,13 +60,7 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal identity.AddClaim(new Claim(ClaimTypes.Email, "someone@antifrogery.com")); identity.AddClaim(new Claim(ClaimTypes.GivenName, "some")); identity.AddClaim(new Claim(ClaimTypes.Surname, "one")); -#if NET46 - // CoreCLR doesn't support an 'empty' name identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, string.Empty)); -#elif NETCOREAPP2_0 -#else -#error Target framework needs to be updated -#endif // Arrange var claimsIdentity = (ClaimsIdentity)identity; diff --git a/test/Microsoft.AspNetCore.Antiforgery.Test/Microsoft.AspNetCore.Antiforgery.Test.csproj b/test/Microsoft.AspNetCore.Antiforgery.Test/Microsoft.AspNetCore.Antiforgery.Test.csproj index f835c84940..52581604da 100644 --- a/test/Microsoft.AspNetCore.Antiforgery.Test/Microsoft.AspNetCore.Antiforgery.Test.csproj +++ b/test/Microsoft.AspNetCore.Antiforgery.Test/Microsoft.AspNetCore.Antiforgery.Test.csproj @@ -3,8 +3,7 @@ - netcoreapp2.0;net46 - netcoreapp2.0 + netcoreapp2.0