add scripts for cdn

change aes mode to cfb in encrypt / decrypt in Security
This commit is contained in:
Alex Bezdieniezhnykh
2025-02-25 19:48:27 +02:00
parent 32955e4c66
commit 6d28085b7e
17 changed files with 104 additions and 7 deletions
+4 -2
View File
@@ -19,10 +19,11 @@ public static class Security
if (key is not { Length: > 0 }) throw new ArgumentNullException(nameof(key));
using var aes = Aes.Create();
aes.Mode = CipherMode.CFB;
aes.Key = SHA256.HashData(Encoding.UTF8.GetBytes(key));
aes.GenerateIV();
using var encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
await using var cs = new CryptoStream(toStream, encryptor, CryptoStreamMode.Write, leaveOpen: true);
// Prepend IV to the encrypted data
@@ -43,8 +44,9 @@ public static class Security
var iv = new byte[aes.BlockSize / 8];
_ = await encryptedStream.ReadAsync(iv, cancellationToken);
aes.IV = iv;
aes.Mode = CipherMode.CFB;
using var decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
await using var cryptoStream = new CryptoStream(encryptedStream, decryptor, CryptoStreamMode.Read, leaveOpen: true);
// Read and write in chunks