-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add .NET 8.0 TFM and use new AesGcm constructor #249
Changes from all commits
91ee937
115740f
aa8530e
370bc40
725d2cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ public class JwtSettings | |
{ | ||
public JwtSettings() | ||
{ | ||
#if NET472 || NETSTANDARD2_1 | ||
#if NET472 || NETSTANDARD2_1 || NET | ||
// By giving the Unix ECDHKeyManagement implementation to windows, we enable windows version of it to work with not only CngKey but also ECDiffieHellman. | ||
// Initially this was implemented separately, but unit tests were failing on windows due to the lack of ECDiffieHellman support. | ||
// Since we don't know what the keys will be provided until runtime, and the registration happens before runtime, we need to make sure | ||
|
@@ -58,7 +58,7 @@ public JwtSettings() | |
{ JwsAlgorithm.ES256, new EcdsaUsingSha(256) }, | ||
{ JwsAlgorithm.ES384, new EcdsaUsingSha(384) }, | ||
{ JwsAlgorithm.ES512, new EcdsaUsingSha(521) } | ||
#elif NETSTANDARD || NET461 || NET472 | ||
#elif NETSTANDARD || NET461 || NET472 || NET | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as mentioned in |
||
{ JwsAlgorithm.ES256, new Jose.netstandard1_4.EcdsaUsingSha(256) }, | ||
{ JwsAlgorithm.ES384, new Jose.netstandard1_4.EcdsaUsingSha(384) }, | ||
{ JwsAlgorithm.ES512, new Jose.netstandard1_4.EcdsaUsingSha(521) } | ||
|
@@ -169,7 +169,7 @@ public JwtSettings() | |
private IJsonMapper jsMapper = new JSSerializerMapper(); | ||
#elif NETSTANDARD1_4 | ||
private IJsonMapper jsMapper = new NewtonsoftMapper(); | ||
#elif NETSTANDARD2_1 | ||
#elif NETSTANDARD2_1 || NET | ||
private IJsonMapper jsMapper = new JsonMapper(); | ||
#endif | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
#if NETSTANDARD2_1 | ||
#if NETSTANDARD2_1 || NET | ||
using System; | ||
using System.Security.Cryptography; | ||
|
||
namespace Jose | ||
{ | ||
public static class AesGcm | ||
{ | ||
public static int FixedTagLength => System.Security.Cryptography.AesGcm.TagByteSizes.MaxSize; // 16 bytes | ||
|
||
/// <summary> | ||
/// Performs AES encryption in GCM chaining mode over plain text | ||
/// </summary> | ||
|
@@ -16,10 +19,15 @@ public static class AesGcm | |
/// /// <exception cref="CryptographicException">if encryption failed by any reason</exception> | ||
public static byte[][] Encrypt(byte[] key, byte[] iv, byte[] aad, byte[] plainText) | ||
{ | ||
#if NET | ||
using var gcm = | ||
new System.Security.Cryptography.AesGcm(key, FixedTagLength); | ||
#elif NETSTANDARD2_1 | ||
using var gcm = new System.Security.Cryptography.AesGcm(key); | ||
#endif | ||
|
||
var ciphertext = new byte[plainText.Length]; | ||
var tag = new byte[System.Security.Cryptography.AesGcm.TagByteSizes.MaxSize]; | ||
var tag = new byte[FixedTagLength]; | ||
|
||
gcm.Encrypt(nonce: iv, plaintext: plainText, ciphertext: ciphertext, tag: tag, associatedData: aad); | ||
|
||
|
@@ -37,7 +45,14 @@ public static byte[][] Encrypt(byte[] key, byte[] iv, byte[] aad, byte[] plainTe | |
/// <exception cref="CryptographicException">if decryption failed by any reason</exception> | ||
public static byte[] Decrypt(byte[] key, byte[] iv, byte[] aad, byte[] cipherText, byte[] authTag) | ||
{ | ||
#if NET | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i guess we can just collapse both branches together now? No need to use .NET 8.0 specific AesGcm() constructor as you check auth tag length explicitly now. And you can leverage And after just clean up all |
||
using var gcm = | ||
new System.Security.Cryptography.AesGcm(key, FixedTagLength); | ||
#elif NETSTANDARD2_1 | ||
if (authTag.Length != FixedTagLength) | ||
throw new ArgumentException("The specified tag is not a valid size for this algorithm (must be " + FixedTagLength + " bytes).", nameof(authTag)); | ||
using var gcm = new System.Security.Cryptography.AesGcm(key); | ||
#endif | ||
|
||
var plaintext = new byte[cipherText.Length]; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't it be
NET8_0
? WhatNET
specifically targets?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NET
targets .NET 5.0 and above.It's just for convenience like e.g. if in the future we want to target .NET 9.0 and beyond, we just need to update the csproj file with
net9.0
andNET
will cover it automatically without addingNET9_0
to every file.