diff --git a/src/Pandatech.Crypto/Aes256.cs b/src/Pandatech.Crypto/Aes256.cs index 6b40420..576b108 100644 --- a/src/Pandatech.Crypto/Aes256.cs +++ b/src/Pandatech.Crypto/Aes256.cs @@ -61,7 +61,8 @@ private byte[] EncryptWithHashInner(string plainText, string? key = null) private byte[] EncryptWithoutHashInner(string plainText, string? key) { key ??= _options.Key; - ValidateText(plainText); + if (plainText == "") + return []; using var aesAlg = Aes.Create(); aesAlg.KeySize = KeySize; aesAlg.Padding = PaddingMode.PKCS7; @@ -111,7 +112,7 @@ public string DecryptWithoutHash(byte[] cipherText, string key) ? "" : DecryptWithoutSkippingHashInner(cipherText, key); } - + public void Decrypt(Stream inputStream, Stream outputStream, string? key = null) { key ??= _options.Key; @@ -135,7 +136,8 @@ public void Decrypt(Stream inputStream, Stream outputStream, string? key = null) private string DecryptWithoutSkippingHashInner(byte[] cipherText, string? key) { key ??= _options.Key; - ValidateCipherText(cipherText); + if (cipherText.Length == 0) + return ""; var iv = cipherText.Take(IvSize).ToArray(); var encrypted = cipherText.Skip(IvSize).ToArray(); @@ -166,19 +168,6 @@ private static void ValidateKey(string key) throw new ArgumentException("Invalid key."); } - private static void ValidateText(string text) - { - if (string.IsNullOrEmpty(text) && text != null) - throw new ArgumentException("Text cannot be null or empty."); - } - - private static void ValidateCipherText(byte[] cipherText) - { - if (cipherText.Length == 0) return; - - if (cipherText == null || cipherText.Length < IvSize) - throw new ArgumentException("Invalid cipher text."); - } private static bool IsBase64String(string s) { diff --git a/src/Pandatech.Crypto/Pandatech.Crypto.csproj b/src/Pandatech.Crypto/Pandatech.Crypto.csproj index fdfcbf7..90a61e3 100644 --- a/src/Pandatech.Crypto/Pandatech.Crypto.csproj +++ b/src/Pandatech.Crypto/Pandatech.Crypto.csproj @@ -8,12 +8,12 @@ MIT pandatech.png Readme.md - 2.4.0 + 2.4.1 Pandatech.Crypto Pandatech, library, encryption, hash, algorythms, security PandaTech.Crypto is a .NET library simplifying common cryptograhic functions. https://github.com/PandaTechAM/be-lib-pandatech-crypto - Aes256 public api has changed which causes breaking changes. Now instead of parameter of adding hash it is introduced totally new method + Aes256 empty string handle