{"id":12896,"library":"blueimp-md5","title":"MD5 Hash Implementation","description":"blueimp-md5 is a pure JavaScript implementation of the MD5 (Message-Digest Algorithm 5) cryptographic hash function. It is compatible with a wide range of environments, including server-side Node.js applications, client-side web browsers, and module loaders such as RequireJS, Browserify, and webpack. The current stable version is 2.19.0. This library is lightweight with zero external dependencies, making it a self-contained utility for generating MD5 hashes. While highly performant for its purpose, it's crucial to note that MD5 is considered cryptographically broken and should not be used for security-sensitive applications like password hashing or digital signatures, where collisions could be exploited. Its typical use cases include data integrity checks or unique ID generation in non-security contexts.","status":"active","version":"2.19.0","language":"javascript","source_language":"en","source_url":"git://github.com/blueimp/JavaScript-MD5","tags":["javascript","md5"],"install":[{"cmd":"npm install blueimp-md5","lang":"bash","label":"npm"},{"cmd":"yarn add blueimp-md5","lang":"bash","label":"yarn"},{"cmd":"pnpm add blueimp-md5","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports the md5 function as its default export for ESM consumption. Named imports will fail.","wrong":"import { md5 } from 'blueimp-md5'","symbol":"md5","correct":"import md5 from 'blueimp-md5'"},{"note":"In CommonJS, the module directly exports the md5 function, so it's assigned to a variable, not destructured.","wrong":"const { md5 } = require('blueimp-md5')","symbol":"md5","correct":"const md5 = require('blueimp-md5')"},{"note":"When included via a script tag in the browser, the `md5` function is exposed globally.","symbol":"md5","correct":"<!-- In HTML --> <script src=\"js/md5.min.js\"></script> // Then in JS: var hash = md5('value')"}],"quickstart":{"code":"import md5 from 'blueimp-md5';\n\n// Calculate hex-encoded MD5 hash of a string\nconst value = 'Hello, Checklist Day!';\nconst hexHash = md5(value);\nconsole.log(`Hex MD5 hash for '${value}': ${hexHash}`);\n\n// Calculate HMAC-MD5 hash with a key\nconst key = 'secret_key';\nconst hmacHash = md5(value, key);\nconsole.log(`HMAC-MD5 hash with key '${key}': ${hmacHash}`);\n\n// Calculate raw MD5 hash\nconst rawHash = md5(value, null, true);\nconsole.log(`Raw MD5 hash for '${value}':`, rawHash.split('').map(c => c.charCodeAt(0).toString(16).padStart(2, '0')).join(''));\n\n// Example of usage in a Node.js HTTP server (original CJS example adapted for illustration)\n// This part demonstrates a typical server-side use case, but the core md5 usage is above.\n// To run this, save as server.mjs and install 'blueimp-md5'.\n/*\nimport http from 'http';\nimport url from 'url';\n\nhttp.createServer((req, res) => {\n  const parsedUrl = url.parse(req.url, true);\n  const query = parsedUrl.query.value || '';\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end(md5(query));\n}).listen(8080, 'localhost', () => {\n  console.log('Server running at http://localhost:8080/');\n  console.log('Try: http://localhost:8080/?value=test');\n});\n*/","lang":"javascript","description":"Demonstrates calculating hex-encoded MD5 hashes, HMAC-MD5 hashes with a key, and raw MD5 outputs for a given string, showing typical API usage."},"warnings":[{"fix":"For security-sensitive applications, migrate to algorithms like SHA-256 (e.g., Node.js `crypto` module) or bcrypt (for passwords).","message":"MD5 is cryptographically broken and should NOT be used for security-sensitive applications such as password hashing, digital signatures, or any context where collision resistance is critical. Consider SHA-256 or bcrypt for secure hashing needs.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always check the third argument when using `md5()`. If `true`, handle the output as a raw byte string. Convert it to hex if needed, e.g., `md5('value', null, true).split('').map(c => c.charCodeAt(0).toString(16).padStart(2, '0')).join('')`.","message":"When using the `raw` output option (third argument `true`), the function returns a string of raw bytes (characters with char codes representing byte values), not a hex-encoded string. This can be unexpected if you assume all outputs are hex.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"When using multiple scripts, be mindful of global namespace pollution. Consider using module bundlers like webpack or Browserify to encapsulate dependencies and avoid global variable conflicts.","message":"In browser environments, including `md5.min.js` via a `<script>` tag adds a global `md5` function. This can lead to naming conflicts if another script also defines `md5` or a similar global variable.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"In browsers, ensure `<script src=\"md5.min.js\"></script>` is present before `md5()` is called. In CommonJS, use `const md5 = require('blueimp-md5')`. In ESM, use `import md5 from 'blueimp-md5'`.","cause":"Attempting to call `md5()` in a browser environment without including the script, or in a Node.js/ESM environment without correctly importing/requiring the module.","error":"ReferenceError: md5 is not defined"},{"fix":"For ESM, use `import md5 from 'blueimp-md5'`. For CommonJS, use `const md5 = require('blueimp-md5')`.","cause":"Incorrect ES module import syntax (e.g., `import { md5 } from 'blueimp-md5'`) or CommonJS destructuring (e.g., `const { md5 } = require('blueimp-md5')`), as the package exports the function as the default.","error":"TypeError: md5 is not a function"},{"fix":"For browser use, either include the library directly via a `<script>` tag or use a module bundler that processes CommonJS `require` statements.","cause":"Attempting to use `require('blueimp-md5')` in a browser environment without a CommonJS-compatible module loader (like Browserify or webpack).","error":"ReferenceError: require is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}