using System;
using System.Security.Cryptography;
using System.Text;
class BasicSecurityCheck
{
// ฟังก์ชันสำหรับการเข้ารหัสข้อมูล
public static string EncryptString(string plainText, string key)
{
using (Aes aesAlg = Aes.Create())
{
aesAlg.Key = Encoding.UTF8.GetBytes(key.PadLeft(32)); // กำหนดคีย์ 32 ไบต์
aesAlg.IV = Encoding.UTF8.GetBytes(key.PadRight(16).Substring(0, 16)); // กำหนด IV 16 ไบต์
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
byte[] encrypted = encryptor.TransformFinalBlock(Encoding.UTF8.GetBytes(plainText), 0, plainText.Length);
return Convert.ToBase64String(encrypted);
}
}
static void Main(string[] args)
{
string plainText = "SensitiveData";
string key = "MySecretKey12345"; // คีย์ที่ใช้ในการเข้ารหัส
string encryptedText = EncryptString(plainText, key);
Console.WriteLine("ข้อมูลที่เข้ารหัส: " + encryptedText);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uU2VjdXJpdHkuQ3J5cHRvZ3JhcGh5Owp1c2luZyBTeXN0ZW0uVGV4dDsKCmNsYXNzIEJhc2ljU2VjdXJpdHlDaGVjawp7CiAgICAvLyDguJ/guLHguIfguIHguYzguIrguLHguJnguKrguLPguKvguKPguLHguJrguIHguLLguKPguYDguILguYnguLLguKPguKvguLHguKrguILguYnguK3guKHguLnguKUKICAgIHB1YmxpYyBzdGF0aWMgc3RyaW5nIEVuY3J5cHRTdHJpbmcoc3RyaW5nIHBsYWluVGV4dCwgc3RyaW5nIGtleSkKICAgIHsKICAgICAgICB1c2luZyAoQWVzIGFlc0FsZyA9IEFlcy5DcmVhdGUoKSkKICAgICAgICB7CiAgICAgICAgICAgIGFlc0FsZy5LZXkgPSBFbmNvZGluZy5VVEY4LkdldEJ5dGVzKGtleS5QYWRMZWZ0KDMyKSk7IC8vIOC4geC4s+C4q+C4meC4lOC4hOC4teC4ouC5jCAzMiDguYTguJrguJXguYwKICAgICAgICAgICAgYWVzQW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