From 28cee59de37124d44a1bd8f703571f1727a330f4 Mon Sep 17 00:00:00 2001 From: manusoft Date: Mon, 25 May 2026 17:39:29 +0400 Subject: [PATCH] Add EncryptionMode to header and validate in reader Introduce EncryptionMode property to FiloHeader, defaulting to "AES-CBC". Set this property in FiloWriter when encryption is enabled. Update FiloReader to validate that only supported encryption modes are used, throwing an exception for unsupported modes. This ensures explicit encryption mode handling in the file container. --- src/Filo/Core/FiloReader.cs | 4 ++-- src/Filo/Core/FiloWriter.cs | 1 + src/Filo/Models/FiloHeader.cs | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Filo/Core/FiloReader.cs b/src/Filo/Core/FiloReader.cs index 75caaf1..5f1c66c 100644 --- a/src/Filo/Core/FiloReader.cs +++ b/src/Filo/Core/FiloReader.cs @@ -192,8 +192,8 @@ public async IAsyncEnumerable StreamFileAsync(string fileName, byte[]? k if (!_fileMap.TryGetValue(fileName, out var entry)) throw new FileNotFoundException($"File '{fileName}' not found in container."); - if (Header.Encryption == "AES256" && key == null) - throw new InvalidOperationException("This container is encrypted. Provide a key."); + if (Header.Encryption == "AES256" && Header.EncryptionMode != "AES-CBC") + throw new InvalidDataException("Unsupported encryption mode."); if (entry.Chunks.Count == 0) yield break; diff --git a/src/Filo/Core/FiloWriter.cs b/src/Filo/Core/FiloWriter.cs index db54a26..8b46172 100644 --- a/src/Filo/Core/FiloWriter.cs +++ b/src/Filo/Core/FiloWriter.cs @@ -111,6 +111,7 @@ public async Task WriteAsync() FileCount = _files.Count, Compression = "none", Encryption = _encrypt ? "AES256" : "none", + EncryptionMode = _encrypt ? "AES-CBC" : null, Kdf = !string.IsNullOrWhiteSpace(_password) ? "PBKDF2" : null, Salt = !string.IsNullOrWhiteSpace(_password) ? Convert.ToBase64String(_salt!) : null, PasswordCheck = _encrypt ? SHA256.HashData(_key!) : null, diff --git a/src/Filo/Models/FiloHeader.cs b/src/Filo/Models/FiloHeader.cs index cea7efe..8a16eaf 100644 --- a/src/Filo/Models/FiloHeader.cs +++ b/src/Filo/Models/FiloHeader.cs @@ -14,6 +14,8 @@ public class FiloHeader public string Encryption { get; set; } = "none"; + public string? EncryptionMode { get; set; } = "AES-CBC"; + public string? Kdf { get; set; } // v1.1 public string? Salt { get; set; } // v1.1