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"
}
パラメータ説明:
パラメータ | 型 | 必須 | 説明 |
---|---|---|---|
text | string | はい | MD5を計算するテキスト内容 |
encoding | string | いいえ | 文字エンコーディング、デフォルトutf8 |
outputFormat | string | いいえ | 出力形式、デフォルト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
リクエストパラメータ:
パラメータ | 型 | 必須 | 説明 |
---|---|---|---|
file | file | はい | 計算するファイル |
outputFormat | string | いいえ | 出力形式、デフォルト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
リクエストパラメータ:
パラメータ | 型 | 必須 | 説明 |
---|---|---|---|
files | file | はい | 計算するファイル配列 |
outputFormat | string | いいえ | 出力形式、デフォルト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
リクエストパラメータ:
パラメータ | 型 | 必須 | 説明 |
---|---|---|---|
file | file | はい | 検証するファイル |
expectedHash | string | はい | 期待されるハッシュ値 |
レスポンス例:
{
"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項目
- リクエスト頻度: 1分間に最大1000回
サポートされている形式
- テキストエンコーディング: UTF-8, ASCII, UTF-16, GBK
- 出力形式: 16進数(大文字小文字), Base64
- ファイルタイプ: すべてのファイルタイプ
最終更新: 2024年1月20日