제어관리 외부 커넥션 설정기능

This commit is contained in:
kjs
2025-09-24 18:23:57 +09:00
parent 0d9ee4c40f
commit b41e645c74
25 changed files with 6775 additions and 209 deletions

View File

@@ -23,8 +23,8 @@ export class PasswordEncryption {
// 암호화 키 생성 (SECRET_KEY를 해시하여 32바이트 키 생성)
const key = crypto.scryptSync(this.SECRET_KEY, "salt", 32);
// 암호화 객체 생성
const cipher = crypto.createCipher("aes-256-cbc", key);
// 암호화 객체 생성 (IV를 명시적으로 사용)
const cipher = crypto.createCipheriv(this.ALGORITHM, key, iv);
// 암호화 실행
let encrypted = cipher.update(password, "utf8", "hex");
@@ -57,14 +57,37 @@ export class PasswordEncryption {
// 암호화 키 생성 (암호화 시와 동일)
const key = crypto.scryptSync(this.SECRET_KEY, "salt", 32);
// 복호화 객체 생성
const decipher = crypto.createDecipher("aes-256-cbc", key);
try {
// 새로운 방식: createDecipheriv 사용 (IV 명시적 사용)
const decipher = crypto.createDecipheriv(this.ALGORITHM, key, iv);
let decrypted = decipher.update(encrypted, "hex", "utf8");
decrypted += decipher.final("utf8");
return decrypted;
} catch (newFormatError: unknown) {
const errorMessage =
newFormatError instanceof Error
? newFormatError.message
: String(newFormatError);
console.warn(
"새로운 복호화 방식 실패, 기존 방식으로 시도:",
errorMessage
);
// 복호화 실행
let decrypted = decipher.update(encrypted, "hex", "utf8");
decrypted += decipher.final("utf8");
return decrypted;
try {
// 기존 방식: createDecipher 사용 (하위 호환성)
const decipher = crypto.createDecipher("aes-256-cbc", key);
let decrypted = decipher.update(encrypted, "hex", "utf8");
decrypted += decipher.final("utf8");
return decrypted;
} catch (oldFormatError: unknown) {
const oldErrorMessage =
oldFormatError instanceof Error
? oldFormatError.message
: String(oldFormatError);
console.error("기존 복호화 방식도 실패:", oldErrorMessage);
throw oldFormatError;
}
}
} catch (error) {
console.error("Password decryption failed:", error);
throw new Error("비밀번호 복호화에 실패했습니다.");