Files
managing-apps/src/Managing.Application.Tests/CryptoHelpersTests.cs
2025-07-17 21:07:10 +07:00

39 lines
1.2 KiB
C#

using System.Security.Cryptography;
using Managing.Core;
using Xunit;
namespace Managing.Application.Tests;
public class CryptoHelpersTests
{
[Fact]
public void EncryptAesGcm_And_DecryptAesGcm_RoundTrip_Works()
{
// Arrange
var secretKey = "KaigenXCowchain"; // 32 bytes
var token = "0xC6327E7191726EDBcaA7f8b7FBec147dc2A5d830-NotOsasa";
// Act
var encrypted = CryptoHelpers.EncryptAesGcm(token, secretKey);
var decrypted = CryptoHelpers.DecryptAesGcm(encrypted, secretKey);
// Assert
Assert.NotNull(encrypted);
Assert.NotEqual(token, encrypted); // Should be encrypted
Assert.Equal(token, decrypted); // Should decrypt to original
}
[Fact]
public void DecryptAesGcm_WithWrongKey_Throws()
{
// Arrange
var secretKey = "supersecretkey1234567890123456";
var wrongKey = "wrongsecretkey6543210987654321";
var token = "0xabcdef-jane";
var encrypted = CryptoHelpers.EncryptAesGcm(token, secretKey);
// Act & Assert
Assert.Throws<CryptographicException>(() =>
CryptoHelpers.DecryptAesGcm(encrypted, wrongKey));
}
}