Initial commit to new repository
This commit is contained in:
87
src/AxCopilot/Services/GuideEncryptor.cs
Normal file
87
src/AxCopilot/Services/GuideEncryptor.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace AxCopilot.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 가이드 HTML 파일 암호화/복호화 유틸리티.
|
||||
/// 고정 AES-256-CBC 키를 사용하여 모든 PC에서 동일하게 작동합니다.
|
||||
/// </summary>
|
||||
public static class GuideEncryptor
|
||||
{
|
||||
// 고정 키 (32바이트 = AES-256) — 앱 내장 가이드 보호용
|
||||
private static readonly byte[] Key =
|
||||
{
|
||||
0x41, 0x58, 0x43, 0x6F, 0x70, 0x69, 0x6C, 0x6F,
|
||||
0x74, 0x47, 0x75, 0x69, 0x64, 0x65, 0x4B, 0x65,
|
||||
0x79, 0x32, 0x30, 0x32, 0x36, 0x53, 0x65, 0x63,
|
||||
0x75, 0x72, 0x65, 0x46, 0x69, 0x78, 0x65, 0x64
|
||||
};
|
||||
|
||||
// 고정 IV (16바이트) — 동일 출력 보장
|
||||
private static readonly byte[] Iv =
|
||||
{
|
||||
0x47, 0x75, 0x69, 0x64, 0x65, 0x49, 0x56, 0x46,
|
||||
0x69, 0x78, 0x65, 0x64, 0x32, 0x30, 0x32, 0x36
|
||||
};
|
||||
|
||||
/// <summary>평문 HTML 파일을 암호화하여 .enc 파일로 저장합니다.</summary>
|
||||
public static void EncryptFile(string inputHtmlPath, string outputEncPath)
|
||||
{
|
||||
var plaintext = File.ReadAllBytes(inputHtmlPath);
|
||||
|
||||
using var aes = Aes.Create();
|
||||
aes.Key = Key;
|
||||
aes.IV = Iv;
|
||||
aes.Mode = CipherMode.CBC;
|
||||
aes.Padding = PaddingMode.PKCS7;
|
||||
|
||||
using var encryptor = aes.CreateEncryptor();
|
||||
var encrypted = encryptor.TransformFinalBlock(plaintext, 0, plaintext.Length);
|
||||
File.WriteAllBytes(outputEncPath, encrypted);
|
||||
}
|
||||
|
||||
/// <summary>암호화된 .enc 파일을 복호화하여 HTML 문자열로 반환합니다.</summary>
|
||||
public static string DecryptToString(string encFilePath)
|
||||
{
|
||||
var encrypted = File.ReadAllBytes(encFilePath);
|
||||
|
||||
using var aes = Aes.Create();
|
||||
aes.Key = Key;
|
||||
aes.IV = Iv;
|
||||
aes.Mode = CipherMode.CBC;
|
||||
aes.Padding = PaddingMode.PKCS7;
|
||||
|
||||
using var decryptor = aes.CreateDecryptor();
|
||||
var decrypted = decryptor.TransformFinalBlock(encrypted, 0, encrypted.Length);
|
||||
return Encoding.UTF8.GetString(decrypted);
|
||||
}
|
||||
|
||||
/// <summary>암호화된 바이트 배열을 복호화하여 HTML 문자열로 반환합니다.</summary>
|
||||
public static string DecryptToString(byte[] encrypted)
|
||||
{
|
||||
using var aes = Aes.Create();
|
||||
aes.Key = Key;
|
||||
aes.IV = Iv;
|
||||
aes.Mode = CipherMode.CBC;
|
||||
aes.Padding = PaddingMode.PKCS7;
|
||||
|
||||
using var decryptor = aes.CreateDecryptor();
|
||||
var decrypted = decryptor.TransformFinalBlock(encrypted, 0, encrypted.Length);
|
||||
return Encoding.UTF8.GetString(decrypted);
|
||||
}
|
||||
|
||||
/// <summary>Assets 폴더의 가이드 파일을 암호화합니다. 빌드 전 수동 실행용.</summary>
|
||||
public static void EncryptGuides(string assetsFolder)
|
||||
{
|
||||
var userGuide = Path.Combine(assetsFolder, "AX Copilot 사용가이드.htm");
|
||||
var devGuide = Path.Combine(assetsFolder, "AX Copilot 개발자가이드.htm");
|
||||
|
||||
if (File.Exists(userGuide))
|
||||
EncryptFile(userGuide, Path.Combine(assetsFolder, "guide_user.enc"));
|
||||
|
||||
if (File.Exists(devGuide))
|
||||
EncryptFile(devGuide, Path.Combine(assetsFolder, "guide_dev.enc"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user