Socket
Socket
Sign inDemoInstall

ts-md5

Package Overview
Dependencies
0
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-md5


Version published
Maintainers
2
Install size
161 kB
Created

Package description

What is ts-md5?

The ts-md5 npm package is a TypeScript implementation of the MD5 hashing algorithm. It allows you to generate MD5 hashes for strings, arrays, and other data types. This package is useful for creating checksums, verifying data integrity, and other cryptographic purposes.

What are ts-md5's main functionalities?

Hashing a String

This feature allows you to generate an MD5 hash from a string. The `hashStr` method takes a string as input and returns its MD5 hash.

const { Md5 } = require('ts-md5');
const hash = Md5.hashStr('Hello World');
console.log(hash); // Outputs the MD5 hash of 'Hello World'

Hashing an Array

This feature allows you to generate an MD5 hash from an array of ASCII values. The `hashAsciiStr` method takes an array of ASCII values as input and returns its MD5 hash.

const { Md5 } = require('ts-md5');
const hash = Md5.hashAsciiStr([72, 101, 108, 108, 111]);
console.log(hash); // Outputs the MD5 hash of the ASCII values for 'Hello'

Incremental Hashing

This feature allows you to perform incremental hashing. You can append strings or arrays in parts and then call the `end` method to get the final MD5 hash.

const { Md5 } = require('ts-md5');
const md5 = new Md5();
md5.appendStr('Hello');
md5.appendStr(' World');
const hash = md5.end();
console.log(hash); // Outputs the MD5 hash of 'Hello World'

Other packages similar to ts-md5

Readme

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

  1. Import the class
    • import {Md5} from 'ts-md5';
  2. 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 src

The project is written in typescript and transpiled into ES5.

  1. Install TypeScript: npm install -g typescript (if you haven't already)
  2. Configure compile options in tsconfig.json
  3. Perform build using: tsc

You can find more information here: https://github.com/Microsoft/TypeScript/wiki/tsconfig.json

Scripts

  1. Build Script: npm run build
  2. Test Script: npm run test

Publishing

  1. Sign up to https://www.npmjs.com/
  2. Configure package.json https://docs.npmjs.com/files/package.json
  3. run npm publish https://docs.npmjs.com/cli/publish

License

MIT

Keywords

FAQs

Last updated on 16 Aug 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc