mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-05-19 13:57:18 -04:00
Prevent error when attempting to encrypt/decrypt empty string (#217)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user