암복호화 도구

개발 목적을 위해 암복호화 도구를 제공합니다.
필요시 링크에서 다운로드 하셔서 사용하시기 바랍니다.
맥OS에서 사용시, 첫 실행때 “개인정보 보호 및 보안” 설정에서 허용을 해주셔야 사용이 가능합니다.
Encrypt Tool Preview

암호화 옵션

쿼리 스트링 암호화 모듈의 종류

암호화 모듈의 종류

쿼리 스트링 암호화

쿼리 스트링 암호화

안전한 데이터 전송 옵션

안전한 데이터 전송 옵션

암/복호화 방식

암/복호화 방식

1. 암호화 모듈의 종류

적용 가능한 암호화 모듈의 종류는 다음 두가지 입니다.
  • AES-256: 빠르고 간단한 블록 암호화 방식
  • GCM-256: 인증 및 무결성 기능을 포함한 강화된 암호화 방식

암호화 키 종류

  • API 키: Project에 부여된 API 키
  • Custom API 키: 라이브폼에서 신규로 발급받아 사용하는 secretKey Encryption modules

2. 쿼리 스트링 암호화

URL의 쿼리 스트링으로 전송되는 민감한 데이터를 AES-256 방식이나 GCM-256 방식으로 암호화합니다.
1

암호화할 데이터를 JSON 형식으로 준비

각 Query String 키에 대한 설명은 다음 링크를 참조하세요.주요 QueryString 파라미터
{
    "email": "email@email.com",
    "userid": "userid",
    "cf1": "value 1",
    "cf2": "value 2",
    "cf3": "value 3",
    "blacklistCountries": false,
    "approvePeriod": false,
    "rejectPeriod": false,
    "ageLimit": false,
    "rejectDuplicateUser": true,
    "token": "token_id",
    "allowedCountries": "USA,KOR"
}
2

암호화 모듈 AES-256/GCM-256 및 API 키 및 secretKey 중 하나를 선택

secretKey의 경우 한번 발급 이후 표시되지 않습니다. 분실 시, 재발급해서 사용해주세요.
3

제공된 API 키로 AES-256/GCM-256 암호화 수행

AES-256 암호화 수행 전에 쿼리 스트링 암호화 및 복호화 단계를 확인해주세요.
secretKey를 발급받은 경우, secretKey를 활용해주세요.
4

암호화된 데이터를 URL의 encrypted 쿼리 파라미터에 추가

https://form.argosidentity.com/?pid={project_Id}&encrypted={encrypted_json_text}
주의: pid, lang 쿼리 스트링 및 ‘추가 프로세스 (Injection)’ 페이지에서 사용하는 sid, action 쿼리 스트링은 암호화를 지원하지 않습니다.

3. 쿼리 스트링 암호화 및 복호화 방법

3-1. 키 생성 프로세스

AES-256 GCM-256
1

Hashed Key 생성

var crypto = require('crypto');
var hashedKey = crypto.createHash('sha256').update(APIKEY).digest();

2

암호화 예시

아래 예시는 데이터를 AES-256 방식으로 암호화하는 방법을 보여줍니다.
  var crypto = require('crypto');

  /**
  * @param {string} data - Stringified JSON data
  * @param {string} apiKey - Project API key
  * @returns {string} Encrypted data
  *
  * 정확한 암호화를 위해선 formatJSON 으로 사용해주세요. 예시는 다음과 같습니다.
  * const data = {
      userid: "10912301",
      email: "email@email.com"
  * };
  *
  * 다음과 같이 직접 string 으로 입력을 피해주세요.
  * 기대한 암호화 결과가 달라질 수 있습니다.
  * `{"userid":"10912301","email":"email@email.com"}`
  */

  function encrypt(data, apiKey) {
    var hashedKey = crypto.createHash('sha256').update(apiKey).digest();
    var cipher = crypto.createCipheriv('aes-256-ecb', hashedKey, null);
    return cipher.update(data, 'utf8', 'base64') + cipher.final('base64');
  }
3

GCM 암호화 예시

아래 예시는 데이터를 AES-256-GCM 방식으로 암호화하는 방법을 보여줍니다.
var crypto = require('crypto');

/**
 * @param {string} data - Stringified JSON data
 * @param {string} apiKey - Project API key
 * @returns {string} Encrypted data in hex format (IV + ciphertext + tag)
 *
 * GCM 모드는 인증된 암호화를 제공하며, IV와 인증 태그가 포함됩니다.
 * 반환값은 12바이트 IV + 암호문 + 16바이트 인증 태그를 hex 문자열로 인코딩한 형태입니다.
 */
function encryptGCM(data, apiKey) {
    var hashedKey = crypto.createHash('sha256').update(apiKey).digest();
    var iv = crypto.randomBytes(12);
    var cipher = crypto.createCipheriv('aes-256-gcm', hashedKey, iv);
    
    var encrypted = cipher.update(data, 'utf8');
    encrypted = Buffer.concat([encrypted, cipher.final()]);
    
    var tag = cipher.getAuthTag();
    var result = Buffer.concat([iv, encrypted, tag]);
    
    return result.toString('hex');
}

/**
 * @param {string} encryptedHex - Hex encoded encrypted data
 * @param {string} apiKey - Project API key
 * @returns {string} Decrypted data
 */
function decryptGCM(encryptedHex, apiKey) {
    var hashedKey = crypto.createHash('sha256').update(apiKey).digest();
    var encryptedBuffer = Buffer.from(encryptedHex, 'hex');
    
    var iv = encryptedBuffer.slice(0, 12);
    var tag = encryptedBuffer.slice(-16);
    var encrypted = encryptedBuffer.slice(12, -16);
    
    var decipher = crypto.createDecipheriv('aes-256-gcm', hashedKey, iv);
    decipher.setAuthTag(tag);
    
    var decrypted = decipher.update(encrypted);
    decrypted = Buffer.concat([decrypted, decipher.final()]);
    
    return decrypted.toString('utf8');
}
4

복호화 예시

아래 예시는 AES-256 방식으로 암호화된 데이터를 복호화하는 방법을 보여줍니다.
    var crypto = require('crypto');

  /**
  * @param {string} encryptedData
  * @param {string} apiKey
  * @returns {string} Decrypted data
  */
  function decrypt(encryptedData, apiKey) {
    var hashedKey = crypto.createHash('sha256').update(apiKey).digest();
    var decipher = crypto.createDecipheriv('aes-256-ecb', hashedKey, null);
    return decipher.update(encryptedData, 'base64', 'utf8') + decipher.final('utf8');
  }

5

GCM 복호화 예시

아래 예시는 AES-256-GCM 방식으로 암호화된 데이터를 복호화하는 방법을 보여줍니다.
var crypto = require('crypto');

/**
 * @param {string} encryptedHex - Hex encoded encrypted data (IV + ciphertext + tag)
 * @param {string} apiKey - Project API key
 * @returns {string} Decrypted data
 */
function decryptGCM(encryptedHex, apiKey) {
    var hashedKey = crypto.createHash('sha256').update(apiKey).digest();
    var encryptedBuffer = Buffer.from(encryptedHex, 'hex');
    
    // IV, 암호문, 태그 분리
    var iv = encryptedBuffer.slice(0, 12);
    var tag = encryptedBuffer.slice(-16);
    var encrypted = encryptedBuffer.slice(12, -16);
    
    var decipher = crypto.createDecipheriv('aes-256-gcm', hashedKey, iv);
    decipher.setAuthTag(tag);
    
    var decrypted = decipher.update(encrypted);
    decrypted = Buffer.concat([decrypted, decipher.final()]);
    
    return decrypted.toString('utf8');
}

4. 안전한 데이터 전송 옵션

API 메서드(GET, POST, PATCH)와 WEBHOOK에서 데이터를 암호화하여 안전하게 전송합니다. API 메서드는 AES-256-ECB 방식을, WEBHOOK은 AES-256-CBC 방식을 사용하여 암호화합니다. 데이터를 안전하게 보호하기 위해 사용 전에 반드시 안전한 데이터 전송 기능이 활성화되어 있는지 확인하세요. 안전한 데이터 전송 기능이 활성화 되어 있을 경우, Request body 는 반드시 암호화하여 전송하여야 합니다. 암호화를 사용할 때: 전체 요청 본문 객체를 암호화합니다. 암호화된 문자열을 body 매개변수로 전송합니다. AES-256-ECB 형태로 암호화가 필요하며, 암호화 방법은 하기 주요 특징과 설명을 참조하세요.
body : encrypt({
		email : 'string',
		fullName : 'string',
		issuingCountry : 'string',
		birthDate: 'string'
		...
	})
응답에는 isEncrypted 플래그와 암호화된 데이터가 포함됩니다.
body : {
    "data": "encrypted-string",
    "isEncrypted": true
}

4-1. 주요 특징

  • GET, POST, PATCH 요청은 AES-256-ECB 방식으로 암호화
  • WEBHOOK 데이터는 AES-256-CBC 방식으로 암호화
  • PKI를 통한 데이터 무결성 및 인증 보장
  • 전송 중 데이터 보호 강화

4-2. API 요청 데이터 암호화 (AES-256-ECB)

const CryptoJS = require('crypto-js');

function encryptECB(data, apiKey) {
    const hashedKey = CryptoJS.SHA256(apiKey);
    const key = CryptoJS.lib.WordArray.create(hashedKey.words.slice(0, 8), 32);
    const encrypted = CryptoJS.AES.encrypt(JSON.stringify(data), key, {
        mode: CryptoJS.mode.ECB
    });
    return encrypted.ciphertext.toString(CryptoJS.enc.Base64);
}

4-3. API 데이터 복호화 (AES-256-ECB)

const CryptoJS = require('crypto-js');

function decryptECB(encryptedData, apiKey) {
    const hashedKey = CryptoJS.SHA256(apiKey);
    const key = CryptoJS.lib.WordArray.create(hashedKey.words.slice(0, 8), 32);
    const cipherParams = CryptoJS.lib.CipherParams.create({
        ciphertext: CryptoJS.enc.Base64.parse(encryptedData)
    });
    const decrypted = CryptoJS.AES.decrypt(cipherParams, key, {
        mode: CryptoJS.mode.ECB
    });
    return JSON.parse(decrypted.toString(CryptoJS.enc.Utf8));
}

4-4. WEBHOOK 데이터 암호화 (AES-256-CBC)

const CryptoJS = require('crypto-js');

function generateKeyAndIV(apiKey) {
    const hashedKey = CryptoJS.SHA256(apiKey);
    const key = CryptoJS.lib.WordArray.create(hashedKey.words.slice(0, 8), 32);
    const iv = CryptoJS.lib.WordArray.create(hashedKey.words.slice(8, 12), 16);
    return { key, iv };
}

function encryptCBC(data, apiKey) {
    const { key, iv } = generateKeyAndIV(apiKey);
    const encrypted = CryptoJS.AES.encrypt(JSON.stringify(data), key, { iv: iv, mode: CryptoJS.mode.CBC });
    return encrypted.ciphertext.toString(CryptoJS.enc.Base64);
}

4-5. WEBHOOK 데이터 복호화 (AES-256-CBC)

const CryptoJS = require('crypto-js');

function generateKeyAndIV(apiKey) {
    const hashedKey = CryptoJS.SHA256(apiKey);
    const key = CryptoJS.lib.WordArray.create(hashedKey.words.slice(0, 8), 32);
    const iv = CryptoJS.lib.WordArray.create(hashedKey.words.slice(8, 12), 16);
    return { key, iv };
}

function decryptCBC(encryptedData, apiKey) {
    const { key, iv } = generateKeyAndIV(apiKey);
    
    // Create cipher params for decryption
    const cipherParams = CryptoJS.lib.CipherParams.create({
        ciphertext: CryptoJS.enc.Base64.parse(encryptedData)
    });
    
    // Decrypt the data
    const decrypted = CryptoJS.AES.decrypt(cipherParams, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });
    
    return JSON.parse(decrypted.toString(CryptoJS.enc.Utf8));
}