npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-digest-md5

v1.0.4

Published

A simple pure-js implementation of DIGEST-MD5. Written for XMPP, but can be used elsewhere.

Downloads

17

Readme

simple-digest-md5

This 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.

NPM NPM

Installation

npm install simple-digest-md5

Usage

This module will calculate the response to a given DIGEST-MD5 challenge, but it won't send it down the wire for you.

To use it do something like this:

var md5_digest = require("simple-md5-digest");

// Initialise socket here & send initial packets

socket.on("data", function(data) {
	// Process incoming message here
	
	// ...
	
	
	// We have get a challenge from the server!
	
	var ch_response = md5_digest.get_response(challenge, "username", "password", "resource");
	
	// Package the response up to send it down the wire here
	
	socket.write(message);
});

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:

var ch_response = md5_digest.get_response(challenge, "username", "password");

This 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.

Note 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:

digest_md5.set_service("service_name_here");

If you have got a challenge encoded as base64, simply use md5_digest.get_response_b64 instead and it will decode the response first.

Using this with XMPP

If you are using this with XMPP, I recommend you read this page, which walks you through the proecss and gives you a sample exchange. For convenience, I will include the sample exchange here:

1 >>> <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/>
1 <<< <challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>cmVhbG09ImNhdGFjbHlzbS5jeCIsbm9uY2U9Ik9BNk1HOXRFUUdtMmhoIixxb3A9ImF1dGgiLGNoYXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNz</challenge>
2 >>> <response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>dXNlcm5hbWU9InJvYiIscmVhbG09ImNhdGFjbHlzbS5jeCIsbm9uY2U9Ik9BNk1HOXRFUUdtMmhoIixjbm9uY2U9Ik9BNk1IWGg2VnFUclJrIixuYz0wMDAwMDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ4bXBwL2NhdGFjbHlzbS5jeCIscmVzcG9uc2U9ZDM4OGRhZDkwZDRiYmQ3NjBhMTUyMzIxZjIxNDNhZjcsY2hhcnNldD11dGYtOCxhdXRoemlkPSJyb2JAY2F0YWNseXNtLmN4L215UmVzb3VyY2Ui</response>
2 <<< <challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>cnNwYXV0aD1lYTQwZjYwMzM1YzQyN2I1NTI3Yjg0ZGJhYmNkZmZmZA==</challenge>
3 >>> <response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
3 <<< <success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>

The 2nd message that you send is the base64 encoded result from digest_md5.get_response().

Advanced Usage

The following functions are also available for use if you need finer control over how this module operates:

  • 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.
  • digest_md5.base64_decode(thing) - Decodes something encoded with base64.
  • digest_md5.parse_challenge(challenge) - Parses a given challenge string into it's component parts.
  • digest_md5.set_service(service_name) - Sets the serivce that you are authenticating with.
  • digest_md5.parse_challenge(challange_str) - Parses a given challange string into its component parts.
  • digest_md5.get_response_raw(parsed_challenge, user, pass, resource) - Calculates a response to a challenge string parsed with the above function.
  • 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.

If 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 :)

Bugs & Support

You can report bugs and / or get help on the GitHub Issue Tracker. I can also be contacted by email.

Credits