Skip to content

Commit

Permalink
Merge pull request #21 from PandaTechAM/development
Browse files Browse the repository at this point in the history
updated nullability issues
  • Loading branch information
HaikAsatryan authored Jun 14, 2024
2 parents a01ef67 + 5e5d4d0 commit ab23260
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
21 changes: 5 additions & 16 deletions src/Pandatech.Crypto/Aes256.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Pandatech.Crypto/Pandatech.Crypto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<Copyright>MIT</Copyright>
<PackageIcon>pandatech.png</PackageIcon>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Version>2.4.0</Version>
<Version>2.4.1</Version>
<Title>Pandatech.Crypto</Title>
<PackageTags>Pandatech, library, encryption, hash, algorythms, security</PackageTags>
<Description>PandaTech.Crypto is a .NET library simplifying common cryptograhic functions.</Description>
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-pandatech-crypto</RepositoryUrl>
<PackageReleaseNotes>Aes256 public api has changed which causes breaking changes. Now instead of parameter of adding hash it is introduced totally new method</PackageReleaseNotes>
<PackageReleaseNotes>Aes256 empty string handle</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit ab23260

Please sign in to comment.