- AesEncryption: AES-256-CBC 암호화/복호화 - RsaEncryption: RSA-2048 키 쌍 생성/암복호화 - E2EEService: 하이브리드 암복호화 (요청 복호화, 응답 암호화) - TimestampValidator: 타임스탬프 검증 (±30초) - SecureTransportAttribute: Action Filter (보안등급 3 엔드포인트용) - DI 등록: IE2EEService → E2EEService (Singleton) Closes #28
45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using System.Security.Cryptography;
|
|
|
|
namespace SPMS.Infrastructure.Security;
|
|
|
|
public static class AesEncryption
|
|
{
|
|
public static byte[] Encrypt(byte[] plaintext, byte[] key, byte[] iv)
|
|
{
|
|
using var aes = Aes.Create();
|
|
aes.Key = key;
|
|
aes.IV = iv;
|
|
aes.Mode = CipherMode.CBC;
|
|
aes.Padding = PaddingMode.PKCS7;
|
|
|
|
using var encryptor = aes.CreateEncryptor();
|
|
return encryptor.TransformFinalBlock(plaintext, 0, plaintext.Length);
|
|
}
|
|
|
|
public static byte[] Decrypt(byte[] ciphertext, byte[] key, byte[] iv)
|
|
{
|
|
using var aes = Aes.Create();
|
|
aes.Key = key;
|
|
aes.IV = iv;
|
|
aes.Mode = CipherMode.CBC;
|
|
aes.Padding = PaddingMode.PKCS7;
|
|
|
|
using var decryptor = aes.CreateDecryptor();
|
|
return decryptor.TransformFinalBlock(ciphertext, 0, ciphertext.Length);
|
|
}
|
|
|
|
public static byte[] GenerateKey()
|
|
{
|
|
var key = new byte[32];
|
|
RandomNumberGenerator.Fill(key);
|
|
return key;
|
|
}
|
|
|
|
public static byte[] GenerateIv()
|
|
{
|
|
var iv = new byte[16];
|
|
RandomNumberGenerator.Fill(iv);
|
|
return iv;
|
|
}
|
|
}
|