using System.Security.Cryptography; namespace ComplianceBLL.Adapter; // Shared AES-256/ECB helper used by GSP adapters (GSTCafe, and any future adapter needing the same // payload/credential encryption scheme) — not tied to any single adapter implementation. public static class AesCryptoHelper { public static byte[] AES256Encrypt(byte[] bytesToBeEncrypted, byte[] passwordBytes) { try { using var ms = new MemoryStream(); using (var aes = Aes.Create()) { aes.Key = passwordBytes; aes.Mode = CipherMode.ECB; // "zero" IV aes.IV = new byte[16]; using var cs = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write); cs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length); cs.Close(); } return ms.ToArray(); } catch { throw; } } public static byte[] AES256Decrypt(byte[] bytesToBeDecrypted, byte[] passwordBytes) { try { using var ms = new MemoryStream(); using (var aes = Aes.Create()) { aes.Key = passwordBytes; aes.Mode = CipherMode.ECB; // "zero" IV aes.IV = new byte[16]; using var cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Write); cs.Write(bytesToBeDecrypted, 0, bytesToBeDecrypted.Length); cs.Close(); } return ms.ToArray(); } catch { throw; } } }