Standard SHA-1 hash function for AI agents and workflows. Note: SHA-1 is broken for collision resistance (SHAttered, 2017) — use SHA-256 for new security code.
Import directly into Dify, Coze, Cursor, or any tool-calling agent runtime.
{
"name": "sha1_hash",
"description": "Compute the SHA-1 hash of a UTF-8 string and return the 40-character lowercase hex digest. SHA-1 is broken for collision resistance; use only for legacy compatibility or non-security fingerprinting.",
"parameters": {
"type": "object",
"properties": {
"input_string": {
"type": "string",
"description": "The raw text to hash. Will be encoded as UTF-8 before hashing."
}
},
"required": ["input_string"]
}
}Paste this into your system prompt to keep the generated tool implementation aligned with the contract.
# Task Constraints: SHA-1 Module
SHA-1 produces a 160-bit (40 hex character) digest. It is broken for collision resistance (CWI / Google demonstrated a practical collision in 2017). Use it ONLY for: Git object IDs, legacy fingerprinting, non-security checksums. NEVER for password storage, code signing, or TLS.
## Core Prohibitions
- NEVER recommend SHA-1 for new cryptographic protocols.
- NEVER use SHA-1 in HMAC constructions for new code (use HMAC-SHA-256).
- NEVER treat the hash as reversible.
## Standard Implementation
1. Encode the input as UTF-8 bytes.
2. Apply SHA-1 per FIPS 180-4 (or call `crypto.subtle.digest('SHA-1', bytes)` in browsers, `crypto.createHash('sha1')` in Node).
3. Return the 40-character lowercase hex digest.
4. Always wrap in try/catch and return `{ success, result, error }`.Works in any Web Crypto / Node 16+ environment. Returns the 40-char hex digest.
async function main(args) {
const { input_string } = args;
if (typeof input_string !== "string") {
return { success: false, result: "", error: "input_string must be a string" };
}
try {
const bytes = new TextEncoder().encode(input_string);
const buf = await crypto.subtle.digest("SHA-1", bytes);
const result = Array.from(new Uint8Array(buf))
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
return { success: true, result, error: "" };
} catch (error) {
return {
success: false,
result: "",
error: "SHA-1 failed: " + (error instanceof Error ? error.message : String(error)),
};
}
}