fix: add preprocessor directives

This commit is contained in:
Stevan Freeborn
2026-04-02 13:50:47 -05:00
parent 33fb8bdf54
commit d6e22f9f24
2 changed files with 15 additions and 1 deletions
@@ -28,7 +28,12 @@ internal sealed class AesCryptoProvider(IEncryptionKeyProvider keyProvider) : IC
var cipherBytes = new byte[plainBytes.Length]; var cipherBytes = new byte[plainBytes.Length];
#if NETSTANDARD2_1
using var aesGcm = new AesGcm(key); using var aesGcm = new AesGcm(key);
#else
using var aesGcm = new AesGcm(key, TagSize);
#endif
aesGcm.Encrypt(nonce, plainBytes, cipherBytes, tag); aesGcm.Encrypt(nonce, plainBytes, cipherBytes, tag);
var combinedBytes = new byte[NonceSize + TagSize + plainBytes.Length]; var combinedBytes = new byte[NonceSize + TagSize + plainBytes.Length];
@@ -51,7 +56,7 @@ internal sealed class AesCryptoProvider(IEncryptionKeyProvider keyProvider) : IC
if (combinedBytes.Length < NonceSize + TagSize) 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]; var nonce = combinedBytes[..NonceSize];
@@ -59,7 +64,12 @@ internal sealed class AesCryptoProvider(IEncryptionKeyProvider keyProvider) : IC
var cipherBytes = combinedBytes[(NonceSize + TagSize)..]; var cipherBytes = combinedBytes[(NonceSize + TagSize)..];
var plainBytes = new byte[cipherBytes.Length]; var plainBytes = new byte[cipherBytes.Length];
#if NETSTANDARD2_1
using var aesGcm = new AesGcm(key); using var aesGcm = new AesGcm(key);
#else
using var aesGcm = new AesGcm(key, TagSize);
#endif
aesGcm.Decrypt(nonce, cipherBytes, tag, plainBytes); aesGcm.Decrypt(nonce, cipherBytes, tag, plainBytes);
return Encoding.UTF8.GetString(plainBytes); return Encoding.UTF8.GetString(plainBytes);
@@ -11,7 +11,11 @@ internal sealed class MachineIdKeyProvider(IMachineIdKeyGenerator generator) : I
{ {
var machineId = _generator.GetId(); var machineId = _generator.GetId();
var @bytes = Encoding.UTF8.GetBytes(machineId); var @bytes = Encoding.UTF8.GetBytes(machineId);
#if NET5_0_OR_GREATER
return SHA256.HashData(@bytes);
#else
using var sha256 = SHA256.Create(); using var sha256 = SHA256.Create();
return sha256.ComputeHash(@bytes); return sha256.ComputeHash(@bytes);
#endif
} }
} }