diff --git a/src/StevanFreeborn.Extensions.Configuration.Secure/Cryptography/AesCryptoProvider.cs b/src/StevanFreeborn.Extensions.Configuration.Secure/Cryptography/AesCryptoProvider.cs index 8cf4e77..e5c6830 100644 --- a/src/StevanFreeborn.Extensions.Configuration.Secure/Cryptography/AesCryptoProvider.cs +++ b/src/StevanFreeborn.Extensions.Configuration.Secure/Cryptography/AesCryptoProvider.cs @@ -28,7 +28,12 @@ internal sealed class AesCryptoProvider(IEncryptionKeyProvider keyProvider) : IC var cipherBytes = new byte[plainBytes.Length]; +#if NETSTANDARD2_1 using var aesGcm = new AesGcm(key); +#else + using var aesGcm = new AesGcm(key, TagSize); +#endif + aesGcm.Encrypt(nonce, plainBytes, cipherBytes, tag); var combinedBytes = new byte[NonceSize + TagSize + plainBytes.Length]; @@ -51,7 +56,7 @@ internal sealed class AesCryptoProvider(IEncryptionKeyProvider keyProvider) : IC if (combinedBytes.Length < NonceSize + TagSize) { - throw new CryptographicException($"Invalid playload. {nameof(cipherText)} is not of expected length"); + throw new CryptographicException($"Invalid payload. {nameof(cipherText)} is not of expected length"); } var nonce = combinedBytes[..NonceSize]; @@ -59,7 +64,12 @@ internal sealed class AesCryptoProvider(IEncryptionKeyProvider keyProvider) : IC var cipherBytes = combinedBytes[(NonceSize + TagSize)..]; var plainBytes = new byte[cipherBytes.Length]; +#if NETSTANDARD2_1 using var aesGcm = new AesGcm(key); +#else + using var aesGcm = new AesGcm(key, TagSize); +#endif + aesGcm.Decrypt(nonce, cipherBytes, tag, plainBytes); return Encoding.UTF8.GetString(plainBytes); diff --git a/src/StevanFreeborn.Extensions.Configuration.Secure/Cryptography/MachineIdKeyProvider.cs b/src/StevanFreeborn.Extensions.Configuration.Secure/Cryptography/MachineIdKeyProvider.cs index cc17a29..a42bc19 100644 --- a/src/StevanFreeborn.Extensions.Configuration.Secure/Cryptography/MachineIdKeyProvider.cs +++ b/src/StevanFreeborn.Extensions.Configuration.Secure/Cryptography/MachineIdKeyProvider.cs @@ -11,7 +11,11 @@ internal sealed class MachineIdKeyProvider(IMachineIdKeyGenerator generator) : I { var machineId = _generator.GetId(); var @bytes = Encoding.UTF8.GetBytes(machineId); +#if NET5_0_OR_GREATER + return SHA256.HashData(@bytes); +#else using var sha256 = SHA256.Create(); return sha256.ComputeHash(@bytes); +#endif } } \ No newline at end of file