API-Referenz
Übersicht
Der MD5-Hash-Rechner bietet eine vollständige RESTful API-Interface, das Textberechnung, Dateiverarbeitung und Batch-Operationen unterstützt.
Grundinformationen
- Basis-URL:
https://api.example.com/md5
- Authentifizierung: API-Schlüssel
- Datenformat: JSON
- Zeichenkodierung: UTF-8
Antwortformat
Alle API-Antworten folgen einem einheitlichen Format:
{
"success": true,
"data": {
// Spezifische Daten
},
"message": "Operation erfolgreich",
"timestamp": "2024-01-20T10:30:00Z"
}
Text-MD5-Berechnung
Text-MD5 berechnen
Endpunkt: POST /api/md5/text
Anfrageparameter:
{
"text": "Zu berechnender Textinhalt",
"encoding": "utf8",
"outputFormat": "hex"
}
Parameterbeschreibung:
Parameter | Typ | Erforderlich | Beschreibung |
---|---|---|---|
text | string | Ja | Zu berechnender Textinhalt für MD5 |
encoding | string | Nein | Zeichenkodierung, Standard utf8 |
outputFormat | string | Nein | Ausgabeformat, Standard hex |
Unterstützte Kodierungsformate:
utf8
: UTF-8-Kodierungascii
: ASCII-Kodierungutf16
: UTF-16-Kodierunggbk
: GBK-Kodierung
Unterstützte Ausgabeformate:
hex
: Kleinbuchstaben-Hexadezimalhex-upper
: Großbuchstaben-Hexadezimalbase64
: Base64-Kodierung
Antwortbeispiel:
{
"success": true,
"data": {
"text": "Hello, World!",
"hash": "65a8e27d8879283831b664bd8b7f0ad4",
"encoding": "utf8",
"outputFormat": "hex",
"length": 32
},
"message": "Berechnung erfolgreich",
"timestamp": "2024-01-20T10:30:00Z"
}
Batch-Textberechnung
Endpunkt: POST /api/md5/text/batch
Anfrageparameter:
{
"texts": ["Text1", "Text2", "Text3"],
"encoding": "utf8",
"outputFormat": "hex"
}
Antwortbeispiel:
{
"success": true,
"data": {
"results": [
{
"text": "Text1",
"hash": "hash1",
"index": 0
},
{
"text": "Text2",
"hash": "hash2",
"index": 1
},
{
"text": "Text3",
"hash": "hash3",
"index": 2
}
],
"total": 3,
"encoding": "utf8",
"outputFormat": "hex"
},
"message": "Batch-Berechnung erfolgreich",
"timestamp": "2024-01-20T10:30:00Z"
}
Datei-MD5-Berechnung
Datei-Upload-Berechnung
Endpunkt: POST /api/md5/file
Anfrageformat: multipart/form-data
Anfrageparameter:
Parameter | Typ | Erforderlich | Beschreibung |
---|---|---|---|
file | file | Ja | Zu berechnende Datei |
outputFormat | string | Nein | Ausgabeformat, Standard hex |
Antwortbeispiel:
{
"success": true,
"data": {
"filename": "example.txt",
"size": 1024,
"hash": "d41d8cd98f00b204e9800998ecf8427e",
"outputFormat": "hex",
"processingTime": 150
},
"message": "Dateiberechnung erfolgreich",
"timestamp": "2024-01-20T10:30:00Z"
}
Batch-Dateiberechnung
Endpunkt: POST /api/md5/file/batch
Anfrageformat: multipart/form-data
Anfrageparameter:
Parameter | Typ | Erforderlich | Beschreibung |
---|---|---|---|
files | file | Ja | Array zu berechnender Dateien |
outputFormat | string | Nein | Ausgabeformat, Standard hex |
Antwortbeispiel:
{
"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": "Batch-Dateiberechnung erfolgreich",
"timestamp": "2024-01-20T10:30:00Z"
}
Hash-Wert-Verifizierung
Hash-Wert verifizieren
Endpunkt: POST /api/md5/verify
Anfrageparameter:
{
"text": "Zu verifizierender Text",
"expectedHash": "Erwarteter Hash-Wert",
"encoding": "utf8"
}
Antwortbeispiel:
{
"success": true,
"data": {
"text": "Hello, World!",
"expectedHash": "65a8e27d8879283831b664bd8b7f0ad4",
"calculatedHash": "65a8e27d8879283831b664bd8b7f0ad4",
"isValid": true,
"encoding": "utf8"
},
"message": "Verifizierung erfolgreich",
"timestamp": "2024-01-20T10:30:00Z"
}
Dateiintegritätsverifizierung
Endpunkt: POST /api/md5/verify/file
Anfrageformat: multipart/form-data
Anfrageparameter:
Parameter | Typ | Erforderlich | Beschreibung |
---|---|---|---|
file | file | Ja | Zu verifizierende Datei |
expectedHash | string | Ja | Erwarteter Hash-Wert |
Antwortbeispiel:
{
"success": true,
"data": {
"filename": "example.txt",
"expectedHash": "d41d8cd98f00b204e9800998ecf8427e",
"calculatedHash": "d41d8cd98f00b204e9800998ecf8427e",
"isValid": true,
"size": 1024
},
"message": "Dateiintegritätsverifizierung erfolgreich",
"timestamp": "2024-01-20T10:30:00Z"
}
Fehlerbehandlung
Fehlerantwortformat
{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Fehlerbeschreibung",
"details": "Detaillierte Fehlerinformationen"
},
"timestamp": "2024-01-20T10:30:00Z"
}
Häufige Fehlercodes
Fehlercode | Beschreibung | HTTP-Statuscode |
---|---|---|
INVALID_INPUT | Ungültige Eingabeparameter | 400 |
FILE_TOO_LARGE | Datei zu groß | 413 |
UNSUPPORTED_ENCODING | Nicht unterstütztes Kodierungsformat | 400 |
INVALID_HASH_FORMAT | Ungültiges Hash-Format | 400 |
RATE_LIMIT_EXCEEDED | Anfragefrequenz überschritten | 429 |
INTERNAL_ERROR | Serverinterner Fehler | 500 |
Verwendungsbeispiele
JavaScript-Beispiel
// Text-MD5 berechnen
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;
};
// Datei-MD5 berechnen
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;
};
// Hash-Wert verifizieren
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-Beispiel
import requests
import json
# Text-MD5 berechnen
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"])
# Datei-MD5 berechnen
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"])
# Hash-Wert verifizieren
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-Beispiel
# Text-MD5 berechnen
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"
}'
# Datei-MD5 berechnen
curl -X POST "https://api.example.com/md5/file" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@example.txt"
# Hash-Wert verifizieren
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"
}'
Einschränkungen
Anfragebeschränkungen
- Textlänge: Maximum 10MB
- Dateigröße: Maximum 100MB
- Batch-Menge: Maximum 100 Elemente
- Anfragefrequenz: Maximum 1000 Anfragen pro Minute
Unterstützte Formate
- Textkodierung: UTF-8, ASCII, UTF-16, GBK
- Ausgabeformat: Hexadezimal (Groß-/Kleinschreibung), Base64
- Dateitypen: Alle Dateitypen
Letzte Aktualisierung: 20. Januar 2024