{"id":16132645,"url":"https://github.com/sbrl/simple-md5-digest","last_synced_at":"2026-05-21T05:02:33.501Z","repository":{"id":57359992,"uuid":"40006135","full_name":"sbrl/simple-md5-digest","owner":"sbrl","description":"A simple pure-js implementation of DIGEST-MD5. Written for XMPP, but can be used elsewhere.","archived":false,"fork":false,"pushed_at":"2017-12-16T18:51:29.000Z","size":15,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-26T22:21:05.575Z","etag":null,"topics":["authentication","challenge-response","md5-digest","xmpp"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sbrl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-31T13:17:25.000Z","updated_at":"2023-01-06T16:03:42.000Z","dependencies_parsed_at":"2022-09-06T22:22:33.883Z","dependency_job_id":null,"html_url":"https://github.com/sbrl/simple-md5-digest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sbrl/simple-md5-digest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbrl%2Fsimple-md5-digest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbrl%2Fsimple-md5-digest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbrl%2Fsimple-md5-digest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbrl%2Fsimple-md5-digest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbrl","download_url":"https://codeload.github.com/sbrl/simple-md5-digest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbrl%2Fsimple-md5-digest/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265787204,"owners_count":23828382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","challenge-response","md5-digest","xmpp"],"created_at":"2024-10-09T22:32:10.223Z","updated_at":"2026-05-21T05:02:27.817Z","avatar_url":"https://github.com/sbrl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"simple-digest-md5\n=================\nThis module implements DIGEST-MD5 in pure javascript. I didn't see any other implementations in pure JS here on npm, so when I wrote one I thought that I would put it up here - hopefully this helps somebody.\n\n[![NPM](https://nodei.co/npm/simple-digest-md5.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/simple-digest-md5/)\n[![NPM](https://nodei.co/npm-dl/simple-digest-md5.png?months=9\u0026height=3)](https://nodei.co/npm/simple-digest-md5/)\n\n\nInstallation\n------------\n\n```bash\nnpm install simple-digest-md5\n```\n\nUsage\n-----\nThis module will calculate the response to a given DIGEST-MD5 challenge, but it won't send it down the wire for you.\n\nTo use it do something like this:\n\n```javascript\nvar md5_digest = require(\"simple-md5-digest\");\n\n// Initialise socket here \u0026 send initial packets\n\nsocket.on(\"data\", function(data) {\n\t// Process incoming message here\n\t\n\t// ...\n\t\n\t\n\t// We have get a challenge from the server!\n\t\n\tvar ch_response = md5_digest.get_response(challenge, \"username\", \"password\", \"resource\");\n\t\n\t// Package the response up to send it down the wire here\n\t\n\tsocket.write(message);\n});\n\n```\n\n**Warning: Some server's don't actually support an `authzid` when using DIGEST_MD5! (e.g. prosody). If this the case, omit the `resource` parameter:**\n\n```javascript\nvar ch_response = md5_digest.get_response(challenge, \"username\", \"password\");\n```\n\nThis will cause `simple-digest-md5` to omit the `authzid` from the response it calculates. Note that the `authzid` is the part that adds support for the resource string.\n\nNote that when calculating the response to a given DIGEST_MD5 challenge, you have to provide the name of the service that you are authenticating with. This module is set up for `xmpp` by default, but you can change it like so:\n\n```javascript\ndigest_md5.set_service(\"service_name_here\");\n```\n\nIf you have got a challenge encoded as base64, simply use `md5_digest.get_response_b64` instead and it will decode the response first.\n\nUsing this with XMPP\n--------------------\n\nIf you are using this with XMPP, I recommend you read [this page](http://web.archive.org/web/20050224191820/http://cataclysm.cx/wip/digest-md5-crash.html), which walks you through the proecss and gives you a sample exchange. For convenience, I will include the sample exchange here:\n\n```\n1 \u003e\u003e\u003e \u003cauth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/\u003e\n1 \u003c\u003c\u003c \u003cchallenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'\u003ecmVhbG09ImNhdGFjbHlzbS5jeCIsbm9uY2U9Ik9BNk1HOXRFUUdtMmhoIixxb3A9ImF1dGgiLGNoYXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNz\u003c/challenge\u003e\n2 \u003e\u003e\u003e \u003cresponse xmlns='urn:ietf:params:xml:ns:xmpp-sasl'\u003edXNlcm5hbWU9InJvYiIscmVhbG09ImNhdGFjbHlzbS5jeCIsbm9uY2U9Ik9BNk1HOXRFUUdtMmhoIixjbm9uY2U9Ik9BNk1IWGg2VnFUclJrIixuYz0wMDAwMDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ4bXBwL2NhdGFjbHlzbS5jeCIscmVzcG9uc2U9ZDM4OGRhZDkwZDRiYmQ3NjBhMTUyMzIxZjIxNDNhZjcsY2hhcnNldD11dGYtOCxhdXRoemlkPSJyb2JAY2F0YWNseXNtLmN4L215UmVzb3VyY2Ui\u003c/response\u003e\n2 \u003c\u003c\u003c \u003cchallenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'\u003ecnNwYXV0aD1lYTQwZjYwMzM1YzQyN2I1NTI3Yjg0ZGJhYmNkZmZmZA==\u003c/challenge\u003e\n3 \u003e\u003e\u003e \u003cresponse xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/\u003e\n3 \u003c\u003c\u003c \u003csuccess xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/\u003e\n```\n\nThe 2nd message that you send is the base64 encoded result from `digest_md5.get_response()`.\n\nAdvanced Usage\n--------------\nThe following functions are also available for use if you need finer control over how this module operates:\n\n - `digest_md5.base64_encode(thing)` - Encodes something to base_64. This is probably useful when sending your response to the server - XMPP at least requires the response encoded at base64.\n - `digest_md5.base64_decode(thing)` - Decodes something encoded with base64.\n - `digest_md5.parse_challenge(challenge)` - Parses a given challenge string into it's component parts.\n - `digest_md5.set_service(service_name)` - Sets the serivce that you are authenticating with.\n - `digest_md5.parse_challenge(challange_str)` - Parses a given challange string into its component parts.\n - `digest_md5.get_response_raw(parsed_challenge, user, pass, resource)` - Calculates a response to a challenge string parsed with the above function.\n - `md5(thing, encoding)` - Calculates the md5 hash of something. Usually that something will be a string. Encoding is set to \"hex\" by default, but you can change it to \"binary\" or anything else you like that `crypto`'s `createHash(\"md5\").digest()` supports.\n\nIf the above explanations don't make sense, simply read the source code located in `index.js` - the functions are extensively documented there. If that still doesn't help, contact me and I will try and help you :)\n\nBugs \u0026 Support\n----\nYou can report bugs and / or get help on the [GitHub Issue Tracker](https://github.com/sbrl/simple-md5-digest/issues). I can also be contacted by email.\n\nCredits\n-------\n - This webpage was used to implement this module: [A crash course in SASL and DIGEST-MD5 for XMPP](http://web.archive.org/web/20050224191820/http://cataclysm.cx/wip/digest-md5-crash.html) by Robert Norris\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbrl%2Fsimple-md5-digest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbrl%2Fsimple-md5-digest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbrl%2Fsimple-md5-digest/lists"}