Prevent error when attempting to encrypt/decrypt empty string (#217)

This commit is contained in:
Leendert de Borst
2024-09-01 15:20:49 +02:00
parent b129a75255
commit 9b250bf83f
2 changed files with 19 additions and 4 deletions

View File

@@ -77,6 +77,7 @@ public class EmailBoxController(IDbContextFactory<AliasServerDbContext> dbContex
{
Id = x.Id,
Subject = x.Subject,
FromDisplay = x.From,
FromDomain = x.FromDomain,
FromLocal = x.FromLocal,
ToDomain = x.ToDomain,

View File

@@ -23,8 +23,15 @@ public sealed class JsInteropService(IJSRuntime jsRuntime)
/// <param name="plaintext">Plain text to encrypt.</param>
/// <param name="encryptionKey">Encryption key to use.</param>
/// <returns>Encrypted ciphertext.</returns>
public async Task<string> SymmetricEncrypt(string plaintext, string encryptionKey) =>
await jsRuntime.InvokeAsync<string>("cryptoInterop.encrypt", plaintext, encryptionKey);
public async Task<string> SymmetricEncrypt(string plaintext, string encryptionKey)
{
if (string.IsNullOrEmpty(plaintext))
{
return plaintext;
}
return await jsRuntime.InvokeAsync<string>("cryptoInterop.encrypt", plaintext, encryptionKey);
}
/// <summary>
/// Symmetrically decrypts a string using the provided encryption key.
@@ -32,8 +39,15 @@ public sealed class JsInteropService(IJSRuntime jsRuntime)
/// <param name="ciphertext">Cipher text to decrypt.</param>
/// <param name="encryptionKey">Encryption key to use.</param>
/// <returns>Encrypted ciphertext.</returns>
public async Task<string> SymmetricDecrypt(string ciphertext, string encryptionKey) =>
await jsRuntime.InvokeAsync<string>("cryptoInterop.decrypt", ciphertext, encryptionKey);
public async Task<string> SymmetricDecrypt(string ciphertext, string encryptionKey)
{
if (string.IsNullOrEmpty(ciphertext))
{
return ciphertext;
}
return await jsRuntime.InvokeAsync<string>("cryptoInterop.decrypt", ciphertext, encryptionKey);
}
/// <summary>
/// Downloads a file from a stream.