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:
Parameter | Tipe | Wajib | Deskripsi |
---|---|---|---|
text | string | Ya | Konten teks yang akan dihitung MD5 |
encoding | string | Tidak | Pengkodean karakter, default utf8 |
outputFormat | string | Tidak | Format output, default hex |
Format Pengkodean yang Didukung:
utf8
: Pengkodean UTF-8ascii
: Pengkodean ASCIIutf16
: Pengkodean UTF-16gbk
: Pengkodean GBK
Format Output yang Didukung:
hex
: Heksadesimal huruf kecilhex-upper
: Heksadesimal huruf besarbase64
: 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:
Parameter | Tipe | Wajib | Deskripsi |
---|---|---|---|
file | file | Ya | File yang akan dihitung |
outputFormat | string | Tidak | Format 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:
Parameter | Tipe | Wajib | Deskripsi |
---|---|---|---|
files | file | Ya | Array file yang akan dihitung |
outputFormat | string | Tidak | Format 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:
Parameter | Tipe | Wajib | Deskripsi |
---|---|---|---|
file | file | Ya | File yang akan diverifikasi |
expectedHash | string | Ya | Nilai 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 Kesalahan | Deskripsi | Kode Status HTTP |
---|---|---|
INVALID_INPUT | Parameter input tidak valid | 400 |
FILE_TOO_LARGE | File terlalu besar | 413 |
UNSUPPORTED_ENCODING | Format pengkodean tidak didukung | 400 |
INVALID_HASH_FORMAT | Format hash tidak valid | 400 |
RATE_LIMIT_EXCEEDED | Batas frekuensi permintaan terlampaui | 429 |
INTERNAL_ERROR | Kesalahan internal server | 500 |
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