using System.Security.Cryptography; using ZB.MOM.WW.CBDDC.Network.Security; using Xunit; namespace ZB.MOM.WW.CBDDC.Network.Tests; public class CryptoHelperTests { /// /// Verifies that encrypted data can be decrypted back to the original payload. /// [Fact] public void EncryptDecrypt_ShouldPreserveData() { // Arrange var key = new byte[32]; // 256 bits RandomNumberGenerator.Fill(key); var original = new byte[] { 1, 2, 3, 4, 5, 255, 0, 10 }; // Act var (ciphertext, iv, tag) = CryptoHelper.Encrypt(original, key); var decrypted = CryptoHelper.Decrypt(ciphertext, iv, tag, key); // Assert decrypted.ShouldBe(original); } /// /// Verifies that decryption fails when ciphertext is tampered with. /// [Fact] public void Decrypt_ShouldFail_IfTampered() { // Arrange var key = new byte[32]; RandomNumberGenerator.Fill(key); var original = new byte[] { 1, 2, 3 }; var (ciphertext, iv, tag) = CryptoHelper.Encrypt(original, key); // Tamper ciphertext ciphertext[0] ^= 0xFF; // Act Action act = () => CryptoHelper.Decrypt(ciphertext, iv, tag, key); // Assert Should.Throw(act); } }