- AesEncryption: AES-256-CBC 암호화/복호화 - RsaEncryption: RSA-2048 키 쌍 생성/암복호화 - E2EEService: 하이브리드 암복호화 (요청 복호화, 응답 암호화) - TimestampValidator: 타임스탬프 검증 (±30초) - SecureTransportAttribute: Action Filter (보안등급 3 엔드포인트용) - DI 등록: IE2EEService → E2EEService (Singleton) Closes #28
33 lines
1.0 KiB
C#
33 lines
1.0 KiB
C#
using System.Security.Cryptography;
|
|
|
|
namespace SPMS.Infrastructure.Security;
|
|
|
|
public static class RsaEncryption
|
|
{
|
|
public static byte[] Decrypt(byte[] encryptedData, string privateKeyPem)
|
|
{
|
|
using var rsa = RSA.Create();
|
|
rsa.ImportFromPem(privateKeyPem);
|
|
return rsa.Decrypt(encryptedData, RSAEncryptionPadding.OaepSHA256);
|
|
}
|
|
|
|
public static byte[] Encrypt(byte[] data, string publicKeyPem)
|
|
{
|
|
using var rsa = RSA.Create();
|
|
rsa.ImportFromPem(publicKeyPem);
|
|
return rsa.Encrypt(data, RSAEncryptionPadding.OaepSHA256);
|
|
}
|
|
|
|
public static (string PublicKeyPem, string PrivateKeyPem) GenerateKeyPair()
|
|
{
|
|
using var rsa = RSA.Create(2048);
|
|
var privateKey = rsa.ExportRSAPrivateKey();
|
|
var publicKey = rsa.ExportRSAPublicKey();
|
|
|
|
var privatePem = new string(PemEncoding.Write("RSA PRIVATE KEY", privateKey));
|
|
var publicPem = new string(PemEncoding.Write("RSA PUBLIC KEY", publicKey));
|
|
|
|
return (publicPem, privatePem);
|
|
}
|
|
}
|