window.postWithHeader = function(url, method, headerKey, headerValue) { fetch(url, { method: method, headers: { [headerKey] : headerValue } }).then(res => { if (res.redirected) { window.location.href = res.url; } }); }; window.fetchWithHeaderAndReturnUrl = async function(url, method, headerKey, headerValue) { try { const response = await fetch(url, { method: method, headers: { [headerKey]: headerValue } }); if (!response.ok) { console.error('API 호출 실패:', response.status, response.statusText); return null; } const data = await response.json(); console.log('API 응답 데이터:', data); return data; } catch (error) { console.error('API 호출 중 오류 발생:', error); return null; } }; window.loadConfig = async function(configFile) { try { console.log('설정 파일 로드 시도:', configFile); const response = await fetch(configFile); if (!response.ok) { console.error('설정 파일 로드 실패:', response.status, response.statusText); return null; } const config = await response.json(); console.log('설정 파일 로드 성공:', configFile); return config; } catch (error) { console.error('설정 파일 로드 중 오류 발생:', error); return null; } }; window.encryptText = async function(text, key, iv) { try { // XOR 암호화 구현 let result = ''; for (let i = 0; i < text.length; i++) { const charCode = text.charCodeAt(i) ^ key.charCodeAt(i % key.length); result += String.fromCharCode(charCode); } // UTF-8로 인코딩 후 Base64로 변환 const utf8Encoder = new TextEncoder(); const bytes = utf8Encoder.encode(result); const base64 = btoa(String.fromCharCode.apply(null, bytes)); return base64; } catch (error) { console.error('암호화 중 오류 발생:', error); throw error; } }; window.decryptText = async function(encryptedText, key, iv) { try { // Base64 디코딩 후 UTF-8 디코딩 const binary = atob(encryptedText); const bytes = new Uint8Array(binary.length); for (let i = 0; i < binary.length; i++) { bytes[i] = binary.charCodeAt(i); } const utf8Decoder = new TextDecoder(); const text = utf8Decoder.decode(bytes); // XOR 복호화 let result = ''; for (let i = 0; i < text.length; i++) { const charCode = text.charCodeAt(i) ^ key.charCodeAt(i % key.length); result += String.fromCharCode(charCode); } return result; } catch (error) { console.error('복호화 중 오류 발생:', error); throw error; } };