🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

ts-md5

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-md5

TypeScript MD5 implementation

latest
Source
npmnpm
Version
2.0.1
Version published
Weekly downloads
601K
2.28%
Maintainers
2
Weekly downloads
 
Created
Source

Introduction

A MD5 implementation for TypeScript

  • Can handle Unicode strings
  • Supports incremental hashing
  • Works with Files and Blobs

This library also includes tools for:

  • Hashing a file or blob
  • A webworker for performing hashing
  • A webworker handler for requesting files or blobs to be hashed
    • promise based
    • files or blobs are queued for processing on the webworker

Based on work by

  • Joseph Myers: http://www.myersdaily.org/joseph/javascript/md5-text.html
  • AndrĂ© Cruz: https://github.com/satazor/SparkMD5
  • Raymond Hill: https://github.com/gorhill/yamd5.js

Usage

Install

Install the node module with npm install ts-md5

Basic Hashing

  • Import the class
    • import {Md5} from 'ts-md5';
  • Hash some things
    • Md5.hashStr('blah blah blah') => hex:string
    • Md5.hashStr('blah blah blah', true) => raw:Int32Array(4)
    • Md5.hashAsciiStr('blah blah blah') => hex:string
    • Md5.hashAsciiStr('blah blah blah', true) => raw:Int32Array(4)

For more complex uses:


md5 = new Md5();

// Append incrementally your file or other input
// Methods are chainable
md5.appendStr('somestring')
    .appendAsciiStr('a different string')
    .appendByteArray(blob);

// Generate the MD5 hex string
md5.end();

Hashing a File

NOTE:: You have to make sure ts-md5/dist/md5_worker.js is made available in your build so it can be accessed directly by a browser It should always remain as a seperate file.


import {ParallelHasher} from 'ts-md5';

let hasher = new ParallelHasher('/path/to/ts-md5/dist/md5_worker.js');
hasher.hash(fileBlob).then(function(result) {
   console.log('md5 of fileBlob is', result);
});

Building from source

Scripts

  • Build Script: npm run build
  • Test Script: npm run test

Publishing

License

MIT

Keywords

placeos

FAQs

Package last updated on 02 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts