w

API 참조

개요

MD5 해시 계산기는 텍스트 계산, 파일 처리 및 배치 작업을 지원하는 완전한 RESTful API 인터페이스를 제공합니다.

기본 정보

  • 기본 URL: https://api.example.com/md5
  • 인증 방식: API Key
  • 데이터 형식: JSON
  • 문자 인코딩: UTF-8

응답 형식

모든 API 응답은 통일된 형식을 따릅니다:

{
  "success": true,
  "data": {
    // 구체적인 데이터
  },
  "message": "작업이 성공했습니다",
  "timestamp": "2024-01-20T10:30:00Z"
}

텍스트 MD5 계산

텍스트 MD5 계산

엔드포인트: POST /api/md5/text

요청 매개변수:

{
  "text": "계산할 텍스트 내용",
  "encoding": "utf8",
  "outputFormat": "hex"
}

매개변수 설명:

매개변수타입필수설명
textstringMD5를 계산할 텍스트 내용
encodingstring아니오문자 인코딩, 기본값 utf8
outputFormatstring아니오출력 형식, 기본값 hex

지원되는 인코딩 형식:

  • utf8: UTF-8 인코딩
  • ascii: ASCII 인코딩
  • utf16: UTF-16 인코딩
  • gbk: GBK 인코딩

지원되는 출력 형식:

  • hex: 소문자 16진수
  • hex-upper: 대문자 16진수
  • base64: Base64 인코딩

응답 예시:

{
  "success": true,
  "data": {
    "text": "Hello, World!",
    "hash": "65a8e27d8879283831b664bd8b7f0ad4",
    "encoding": "utf8",
    "outputFormat": "hex",
    "length": 32
  },
  "message": "계산이 성공했습니다",
  "timestamp": "2024-01-20T10:30:00Z"
}

배치 텍스트 계산

엔드포인트: POST /api/md5/text/batch

요청 매개변수:

{
  "texts": ["텍스트1", "텍스트2", "텍스트3"],
  "encoding": "utf8",
  "outputFormat": "hex"
}

응답 예시:

{
  "success": true,
  "data": {
    "results": [
      {
        "text": "텍스트1",
        "hash": "hash1",
        "index": 0
      },
      {
        "text": "텍스트2",
        "hash": "hash2",
        "index": 1
      },
      {
        "text": "텍스트3",
        "hash": "hash3",
        "index": 2
      }
    ],
    "total": 3,
    "encoding": "utf8",
    "outputFormat": "hex"
  },
  "message": "배치 계산이 성공했습니다",
  "timestamp": "2024-01-20T10:30:00Z"
}

파일 MD5 계산

파일 업로드 계산

엔드포인트: POST /api/md5/file

요청 형식: multipart/form-data

요청 매개변수:

매개변수타입필수설명
filefile계산할 파일
outputFormatstring아니오출력 형식, 기본값 hex

응답 예시:

{
  "success": true,
  "data": {
    "filename": "example.txt",
    "size": 1024,
    "hash": "d41d8cd98f00b204e9800998ecf8427e",
    "outputFormat": "hex",
    "processingTime": 150
  },
  "message": "파일 계산이 성공했습니다",
  "timestamp": "2024-01-20T10:30:00Z"
}

배치 파일 계산

엔드포인트: POST /api/md5/file/batch

요청 형식: multipart/form-data

요청 매개변수:

매개변수타입필수설명
filesfile계산할 파일 배열
outputFormatstring아니오출력 형식, 기본값 hex

응답 예시:

{
  "success": true,
  "data": {
    "results": [
      {
        "filename": "file1.txt",
        "size": 1024,
        "hash": "hash1",
        "processingTime": 150
      },
      {
        "filename": "file2.txt",
        "size": 2048,
        "hash": "hash2",
        "processingTime": 200
      }
    ],
    "total": 2,
    "totalSize": 3072,
    "totalTime": 350
  },
  "message": "배치 파일 계산이 성공했습니다",
  "timestamp": "2024-01-20T10:30:00Z"
}

해시 값 검증

해시 값 검증

엔드포인트: POST /api/md5/verify

요청 매개변수:

{
  "text": "검증할 텍스트",
  "expectedHash": "예상되는 해시 값",
  "encoding": "utf8"
}

응답 예시:

{
  "success": true,
  "data": {
    "text": "Hello, World!",
    "expectedHash": "65a8e27d8879283831b664bd8b7f0ad4",
    "calculatedHash": "65a8e27d8879283831b664bd8b7f0ad4",
    "isValid": true,
    "encoding": "utf8"
  },
  "message": "검증이 성공했습니다",
  "timestamp": "2024-01-20T10:30:00Z"
}

파일 무결성 검증

엔드포인트: POST /api/md5/verify/file

요청 형식: multipart/form-data

요청 매개변수:

매개변수타입필수설명
filefile검증할 파일
expectedHashstring예상되는 해시 값

응답 예시:

{
  "success": true,
  "data": {
    "filename": "example.txt",
    "expectedHash": "d41d8cd98f00b204e9800998ecf8427e",
    "calculatedHash": "d41d8cd98f00b204e9800998ecf8427e",
    "isValid": true,
    "size": 1024
  },
  "message": "파일 무결성 검증이 성공했습니다",
  "timestamp": "2024-01-20T10:30:00Z"
}

오류 처리

오류 응답 형식

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "오류 설명",
    "details": "상세 오류 정보"
  },
  "timestamp": "2024-01-20T10:30:00Z"
}

일반적인 오류 코드

오류 코드설명HTTP 상태 코드
INVALID_INPUT입력 매개변수가 유효하지 않음400
FILE_TOO_LARGE파일이 너무 큼413
UNSUPPORTED_ENCODING지원되지 않는 인코딩 형식400
INVALID_HASH_FORMAT해시 값 형식이 유효하지 않음400
RATE_LIMIT_EXCEEDED요청 빈도 제한 초과429
INTERNAL_ERROR서버 내부 오류500

사용 예시

JavaScript 예시

// 텍스트 MD5 계산
const calculateTextMD5 = async (text) => {
  const response = await fetch('/api/md5/text', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: 'Bearer YOUR_API_KEY',
    },
    body: JSON.stringify({
      text,
      encoding: 'utf8',
      outputFormat: 'hex',
    }),
  });

  const result = await response.json();
  return result.data.hash;
};

// 파일 MD5 계산
const calculateFileMD5 = async (file) => {
  const formData = new FormData();
  formData.append('file', file);

  const response = await fetch('/api/md5/file', {
    method: 'POST',
    headers: {
      Authorization: 'Bearer YOUR_API_KEY',
    },
    body: formData,
  });

  const result = await response.json();
  return result.data.hash;
};

// 해시 값 검증
const verifyHash = async (text, expectedHash) => {
  const response = await fetch('/api/md5/verify', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: 'Bearer YOUR_API_KEY',
    },
    body: JSON.stringify({
      text,
      expectedHash,
      encoding: 'utf8',
    }),
  });

  const result = await response.json();
  return result.data.isValid;
};

Python 예시

import requests
import json

# 텍스트 MD5 계산
def calculate_text_md5(text, api_key):
    url = "https://api.example.com/md5/text"
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {api_key}"
    }
    data = {
        "text": text,
        "encoding": "utf8",
        "outputFormat": "hex"
    }

    response = requests.post(url, headers=headers, json=data)
    result = response.json()

    if result["success"]:
        return result["data"]["hash"]
    else:
        raise Exception(result["error"]["message"])

# 파일 MD5 계산
def calculate_file_md5(file_path, api_key):
    url = "https://api.example.com/md5/file"
    headers = {
        "Authorization": f"Bearer {api_key}"
    }

    with open(file_path, 'rb') as file:
        files = {'file': file}
        response = requests.post(url, headers=headers, files=files)

    result = response.json()

    if result["success"]:
        return result["data"]["hash"]
    else:
        raise Exception(result["error"]["message"])

# 해시 값 검증
def verify_hash(text, expected_hash, api_key):
    url = "https://api.example.com/md5/verify"
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {api_key}"
    }
    data = {
        "text": text,
        "expectedHash": expected_hash,
        "encoding": "utf8"
    }

    response = requests.post(url, headers=headers, json=data)
    result = response.json()

    if result["success"]:
        return result["data"]["isValid"]
    else:
        raise Exception(result["error"]["message"])

cURL 예시

# 텍스트 MD5 계산
curl -X POST "https://api.example.com/md5/text" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "text": "Hello, World!",
    "encoding": "utf8",
    "outputFormat": "hex"
  }'

# 파일 MD5 계산
curl -X POST "https://api.example.com/md5/file" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@example.txt"

# 해시 값 검증
curl -X POST "https://api.example.com/md5/verify" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "text": "Hello, World!",
    "expectedHash": "65a8e27d8879283831b664bd8b7f0ad4",
    "encoding": "utf8"
  }'

제한 사항

요청 제한

  • 텍스트 길이: 최대 10MB
  • 파일 크기: 최대 100MB
  • 배치 수량: 최대 100개 항목
  • 요청 빈도: 분당 최대 1000회

지원되는 형식

  • 텍스트 인코딩: UTF-8, ASCII, UTF-16, GBK
  • 출력 형식: 16진수(대소문자), Base64
  • 파일 타입: 모든 파일 타입

마지막 업데이트: 2024년 1월 20일

Was this page helpful?