Add encryption for Kaigen server auth
This commit is contained in:
39
src/Managing.Application.Tests/CryptoHelpersTests.cs
Normal file
39
src/Managing.Application.Tests/CryptoHelpersTests.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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 = "supersecretkey1234567890123456"; // 32 bytes
|
||||
var token = "0x1234567890abcdef-johndoe";
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user