Skip to content

Commit 2bb4a70

Browse files
authored
Merge pull request #33 from PandaTechAM/development
Nuget updates
2 parents 9c969d0 + ced9ff4 commit 2bb4a70

File tree

4 files changed

+64
-16
lines changed

4 files changed

+64
-16
lines changed

src/Pandatech.Crypto/Helpers/Mask.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
using RegexBox;
1+
using System.Net.Mail;
22

33
namespace Pandatech.Crypto.Helpers;
44

55
public static class Mask
66
{
77
public static string MaskEmail(this string email)
88
{
9-
if (!PandaValidator.IsEmail(email))
9+
try
1010
{
11-
throw new ArgumentException("Invalid email address", nameof(email));
12-
}
11+
if (!MailAddress.TryCreate(email, out _))
12+
{
13+
throw new ArgumentException("Invalid email format", nameof(email));
14+
}
1315

14-
var parts = email.Split('@');
15-
var localPart = parts[0];
16-
var domainPart = parts[1];
16+
var parts = email.Split('@');
17+
var localPart = parts[0];
18+
var domainPart = parts[1];
1719

18-
var maskedLocalPart =
19-
localPart.Length <= 2 ? localPart : localPart[..2] + new string('*', localPart.Length - 2);
20-
return $"{maskedLocalPart}@{domainPart}";
20+
var maskedLocalPart =
21+
localPart.Length <= 2 ? localPart : localPart[..2] + new string('*', localPart.Length - 2);
22+
return $"{maskedLocalPart}@{domainPart}";
23+
}
24+
catch (Exception ex)
25+
{
26+
throw new ArgumentException("Invalid email format", nameof(email), ex);
27+
}
2128
}
2229

2330
public static string MaskPhoneNumber(this string phoneNumber)

src/Pandatech.Crypto/Pandatech.Crypto.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
<Copyright>MIT</Copyright>
99
<PackageIcon>pandatech.png</PackageIcon>
1010
<PackageReadmeFile>Readme.md</PackageReadmeFile>
11-
<Version>5.0.1</Version>
11+
<Version>5.0.2</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>
1515
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-pandatech-crypto</RepositoryUrl>
16-
<PackageReleaseNotes>AES256 is now replaced by a new AES-SIV implementation for deterministic and authenticated encryption. The old Aes256 class is deprecated due to security concerns, and the new AesMigration class helps convert existing Aes256 ciphertext to the AES-SIV format. The readme has been updated with code samples and usage recommendations.</PackageReleaseNotes>
16+
<PackageReleaseNotes>Nuget updates</PackageReleaseNotes>
1717
</PropertyGroup>
1818

1919
<ItemGroup>
@@ -24,8 +24,7 @@
2424
<ItemGroup>
2525
<PackageReference Include="BouncyCastle.NetCore" Version="2.2.1"/>
2626
<PackageReference Include="Konscious.Security.Cryptography.Argon2" Version="1.3.1"/>
27-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.4"/>
28-
<PackageReference Include="Pandatech.RegexBox" Version="3.0.1"/>
27+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.5" />
2928
</ItemGroup>
3029

3130
</Project>

test/Pandatech.Crypto.Tests/Aes256SivTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,46 @@ public void DecryptStream_InvalidKey_ThrowsArgumentException()
223223
// Act & Assert
224224
Assert.Throws<ArgumentException>(() => Aes256Siv.Decrypt(input, output, invalidKey));
225225
}
226+
227+
[Fact]
228+
public void ExportImport_Base64Utf8_RoundTrip_Succeeds()
229+
{
230+
// Arrange
231+
var key = Random.GenerateAes256KeyString();
232+
const string original = "Payload with ünicode 🌐 and line\r\nbreaks";
233+
234+
// --- export side ----------------------------------------------------
235+
var cipher = Aes256Siv.Encrypt(original, key); // byte[]
236+
var base64 = Convert.ToBase64String(cipher); // string
237+
var fileBytes = Encoding.UTF8.GetBytes(base64); // byte[]
238+
239+
// --- import side ----------------------------------------------------
240+
var base64FromFile = Encoding.UTF8.GetString(fileBytes); // string
241+
var cipherFromFile = Convert.FromBase64String(base64FromFile); // byte[]
242+
var decrypted = Aes256Siv.Decrypt(cipherFromFile, key); // string
243+
244+
// Assert
245+
Assert.Equal(original, decrypted);
246+
}
247+
248+
[Fact]
249+
public void ExportImport_RawBinary_RoundTrip_Succeeds()
250+
{
251+
// Arrange
252+
var key = Random.GenerateAes256KeyString();
253+
const string original = "Binary-only pipeline";
254+
255+
// --- export side ----------------------------------------------------
256+
var cipher = Aes256Siv.Encrypt(original, key); // byte[]
257+
// (write cipher directly to *.pandavault)
258+
259+
// --- import side ----------------------------------------------------
260+
var decrypted = Aes256Siv.Decrypt(cipher, key); // byte[]
261+
262+
// Assert
263+
Assert.Equal(original, decrypted);
264+
}
265+
266+
267+
226268
}

test/Pandatech.Crypto.Tests/Pandatech.Crypto.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="FluentAssertions" Version="[7.1.0]" />
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
1515
<PackageReference Include="xunit" Version="2.9.3" />
16-
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
16+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
<PrivateAssets>all</PrivateAssets>
1919
</PackageReference>

0 commit comments

Comments
 (0)