w

Referensi API

Ikhtisar

Kalkulator hash MD5 menyediakan antarmuka API RESTful lengkap yang mendukung perhitungan teks, pemrosesan file, dan operasi batch.

Informasi Dasar

  • URL Dasar: https://api.example.com/md5
  • Autentikasi: Kunci API
  • Format Data: JSON
  • Pengkodean Karakter: UTF-8

Format Respons

Semua respons API mengikuti format yang seragam:

{
  "success": true,
  "data": {
    // Data spesifik
  },
  "message": "Operasi berhasil",
  "timestamp": "2024-01-20T10:30:00Z"
}

Perhitungan MD5 Teks

Menghitung MD5 Teks

Endpoint: POST /api/md5/text

Parameter Permintaan:

{
  "text": "Konten teks yang akan dihitung",
  "encoding": "utf8",
  "outputFormat": "hex"
}

Deskripsi Parameter:

ParameterTipeWajibDeskripsi
textstringYaKonten teks yang akan dihitung MD5
encodingstringTidakPengkodean karakter, default utf8
outputFormatstringTidakFormat output, default hex

Format Pengkodean yang Didukung:

  • utf8: Pengkodean UTF-8
  • ascii: Pengkodean ASCII
  • utf16: Pengkodean UTF-16
  • gbk: Pengkodean GBK

Format Output yang Didukung:

  • hex: Heksadesimal huruf kecil
  • hex-upper: Heksadesimal huruf besar
  • base64: Pengkodean Base64

Contoh Respons:

{
  "success": true,
  "data": {
    "text": "Hello, World!",
    "hash": "65a8e27d8879283831b664bd8b7f0ad4",
    "encoding": "utf8",
    "outputFormat": "hex",
    "length": 32
  },
  "message": "Perhitungan berhasil",
  "timestamp": "2024-01-20T10:30:00Z"
}

Perhitungan Teks Batch

Endpoint: POST /api/md5/text/batch

Parameter Permintaan:

{
  "texts": ["Teks1", "Teks2", "Teks3"],
  "encoding": "utf8",
  "outputFormat": "hex"
}

Contoh Respons:

{
  "success": true,
  "data": {
    "results": [
      {
        "text": "Teks1",
        "hash": "hash1",
        "index": 0
      },
      {
        "text": "Teks2",
        "hash": "hash2",
        "index": 1
      },
      {
        "text": "Teks3",
        "hash": "hash3",
        "index": 2
      }
    ],
    "total": 3,
    "encoding": "utf8",
    "outputFormat": "hex"
  },
  "message": "Perhitungan batch berhasil",
  "timestamp": "2024-01-20T10:30:00Z"
}

Perhitungan MD5 File

Perhitungan File Upload

Endpoint: POST /api/md5/file

Format Permintaan: multipart/form-data

Parameter Permintaan:

ParameterTipeWajibDeskripsi
filefileYaFile yang akan dihitung
outputFormatstringTidakFormat output, default hex

Contoh Respons:

{
  "success": true,
  "data": {
    "filename": "example.txt",
    "size": 1024,
    "hash": "d41d8cd98f00b204e9800998ecf8427e",
    "outputFormat": "hex",
    "processingTime": 150
  },
  "message": "Perhitungan file berhasil",
  "timestamp": "2024-01-20T10:30:00Z"
}

Perhitungan File Batch

Endpoint: POST /api/md5/file/batch

Format Permintaan: multipart/form-data

Parameter Permintaan:

ParameterTipeWajibDeskripsi
filesfileYaArray file yang akan dihitung
outputFormatstringTidakFormat output, default hex

Contoh Respons:

{
  "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": "Perhitungan file batch berhasil",
  "timestamp": "2024-01-20T10:30:00Z"
}

Verifikasi Nilai Hash

Verifikasi Nilai Hash

Endpoint: POST /api/md5/verify

Parameter Permintaan:

{
  "text": "Teks yang akan diverifikasi",
  "expectedHash": "Nilai hash yang diharapkan",
  "encoding": "utf8"
}

Contoh Respons:

{
  "success": true,
  "data": {
    "text": "Hello, World!",
    "expectedHash": "65a8e27d8879283831b664bd8b7f0ad4",
    "calculatedHash": "65a8e27d8879283831b664bd8b7f0ad4",
    "isValid": true,
    "encoding": "utf8"
  },
  "message": "Verifikasi berhasil",
  "timestamp": "2024-01-20T10:30:00Z"
}

Verifikasi Integritas File

Endpoint: POST /api/md5/verify/file

Format Permintaan: multipart/form-data

Parameter Permintaan:

ParameterTipeWajibDeskripsi
filefileYaFile yang akan diverifikasi
expectedHashstringYaNilai hash yang diharapkan

Contoh Respons:

{
  "success": true,
  "data": {
    "filename": "example.txt",
    "expectedHash": "d41d8cd98f00b204e9800998ecf8427e",
    "calculatedHash": "d41d8cd98f00b204e9800998ecf8427e",
    "isValid": true,
    "size": 1024
  },
  "message": "Verifikasi integritas file berhasil",
  "timestamp": "2024-01-20T10:30:00Z"
}

Penanganan Kesalahan

Format Respons Kesalahan

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "Deskripsi kesalahan",
    "details": "Informasi kesalahan detail"
  },
  "timestamp": "2024-01-20T10:30:00Z"
}

Kode Kesalahan Umum

Kode KesalahanDeskripsiKode Status HTTP
INVALID_INPUTParameter input tidak valid400
FILE_TOO_LARGEFile terlalu besar413
UNSUPPORTED_ENCODINGFormat pengkodean tidak didukung400
INVALID_HASH_FORMATFormat hash tidak valid400
RATE_LIMIT_EXCEEDEDBatas frekuensi permintaan terlampaui429
INTERNAL_ERRORKesalahan internal server500

Contoh Penggunaan

Contoh JavaScript

// Menghitung MD5 teks
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;
};

// Menghitung MD5 file
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;
};

// Verifikasi nilai 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;
};

Contoh Python

import requests
import json

# Menghitung MD5 teks
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"])

# Menghitung MD5 file
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"])

# Verifikasi nilai hash
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"])

Contoh cURL

# Menghitung MD5 teks
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"
  }'

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

# Verifikasi nilai hash
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"
  }'

Batasan

Batasan Permintaan

  • Panjang teks: Maksimal 10MB
  • Ukuran file: Maksimal 100MB
  • Jumlah batch: Maksimal 100 item
  • Frekuensi permintaan: Maksimal 1000 permintaan per menit

Format yang Didukung

  • Pengkodean teks: UTF-8, ASCII, UTF-16, GBK
  • Format output: Heksadesimal (huruf besar/kecil), Base64
  • Jenis file: Semua jenis file

Terakhir Diperbarui: 20 Januari 2024

Was this page helpful?