Skip to content

Commit 624626c

Browse files
MnatsakanMargaryanMnatsakanMargaryan
authored andcommitted
Enhance Aes256Siv with overloads and update version
Updated the `Aes256Siv` class to include multiple overloads for `Encrypt` and `Decrypt` methods, supporting strings, byte arrays, and streams. Default key parameters were added for easier usage, along with a new `DecryptToBytes` method. Incremented version in `Pandatech.Crypto.csproj` from `5.0.0` to `5.0.1` and updated release notes to reflect the new AES-SIV implementation, replacing the deprecated AES256 class due to security concerns.
1 parent 1779bc6 commit 624626c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Pandatech.Crypto/Helpers/Aes256Siv.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@ internal static void RegisterKey(string key)
2020
GlobalKey = key;
2121
}
2222

23+
public static byte[] Encrypt(string plaintext)
24+
{
25+
return Encrypt(plaintext, null);
26+
}
27+
2328
public static byte[] Encrypt(string plaintext, string? key = null)
2429
{
2530
var bytes = Encoding.UTF8.GetBytes(plaintext);
2631
return Encrypt(bytes, key);
2732
}
2833

34+
public static byte[] Encrypt(byte[] plaintext)
35+
{
36+
return Encrypt(plaintext, null);
37+
}
38+
2939
public static byte[] Encrypt(byte[] plaintext, string? key = null)
3040
{
3141
if (plaintext.Length == 0)
@@ -42,6 +52,11 @@ public static byte[] Encrypt(byte[] plaintext, string? key = null)
4252
return Arrays.Concatenate(siv, cipher);
4353
}
4454

55+
public static void Encrypt(Stream input, Stream output)
56+
{
57+
Encrypt(input, output, null);
58+
}
59+
4560
public static void Encrypt(Stream input, Stream output, string? key = null)
4661
{
4762
ArgumentNullException.ThrowIfNull(input);
@@ -53,12 +68,22 @@ public static void Encrypt(Stream input, Stream output, string? key = null)
5368
output.Write(encrypted, 0, encrypted.Length);
5469
}
5570

71+
public static string Decrypt(byte[] ciphertext)
72+
{
73+
return Decrypt(ciphertext, null);
74+
}
75+
5676
public static string Decrypt(byte[] ciphertext, string? key = null)
5777
{
5878
var plain = DecryptToBytes(ciphertext, key);
5979
return Encoding.UTF8.GetString(plain);
6080
}
6181

82+
public static byte[] DecryptToBytes(byte[] ciphertext)
83+
{
84+
return DecryptToBytes(ciphertext, null);
85+
}
86+
6287
public static byte[] DecryptToBytes(byte[] ciphertext, string? key = null)
6388
{
6489
var keyBytes = GetKeyBytes(key);
@@ -86,6 +111,11 @@ public static byte[] DecryptToBytes(byte[] ciphertext, string? key = null)
86111
return plain;
87112
}
88113

114+
public static void Decrypt(Stream input, Stream output)
115+
{
116+
Decrypt(input, output, null);
117+
}
118+
89119
public static void Decrypt(Stream input, Stream output, string? key = null)
90120
{
91121
ArgumentNullException.ThrowIfNull(input);

src/Pandatech.Crypto/Pandatech.Crypto.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<Copyright>MIT</Copyright>
99
<PackageIcon>pandatech.png</PackageIcon>
1010
<PackageReadmeFile>Readme.md</PackageReadmeFile>
11-
<Version>5.0.0</Version>
11+
<Version>5.0.1</Version>
1212
<Title>Pandatech.Crypto</Title>
1313
<PackageTags>Pandatech, library, encryption, hash, algorythms, security</PackageTags>
1414
<Description>PandaTech.Crypto is a .NET library simplifying common cryptograhic functions.</Description>

0 commit comments

Comments
 (0)