Files
psg-oversight-app/OversightService/EncryptionHelper.cs
sonderau d880ebeedb Migration to a ServiceWorker for most tasks.
Implementation of basic PatchComplianceTask. First real iteration, basic/raw asf.
2025-11-04 13:55:04 +08:00

37 lines
1.3 KiB
C#

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace OversightService
{
public class EncryptionHelper
{
private static readonly byte[] Key = Encoding.UTF8.GetBytes("HWJGbwmF2pWdXySDExMNEbJSrXn0YCBF"); // 32 bytes for AES-256
private static readonly byte[] IV = Encoding.UTF8.GetBytes("VWYRtYCfch0sKs6k"); // 16 bytes
public static string EncryptData(string plainText)
{
using (Aes aes = Aes.Create())
{
aes.Key = Key;
aes.IV = IV;
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;
using (MemoryStream ms = new MemoryStream())
using (CryptoStream cs = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write))
{
using (StreamWriter sw = new StreamWriter(cs, new UTF8Encoding(false))) // Disable BOM
{
sw.Write(plainText);
}
byte[] encryptedBytes = ms.ToArray();
string encryptedBase64 = Convert.ToBase64String(encryptedBytes);
return encryptedBase64;
}
}
}
}
}