Skip to content

Synchronously return a digest generated from the given hash function and data

Notifications You must be signed in to change notification settings

LinusU/crypto-digest-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Synchronous crypto.subtle.digest

Synchronously return a digest generated from the given hash function and data.

Installation

npm install --save crypto-digest-sync

Usage

const digestSync = require('crypto-digest-sync')

const arrayBufferToHex = require('array-buffer-to-hex')
const encodeUtf8 = require('encode-utf8')

const input = encodeUtf8('Hello, World!')
const hash = digestSync('SHA-256', input)

console.log(arrayBufferToHex(hash))
//=> dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f

API

digestSync(algo: string, buffer: ArrayBuffer): ArrayBuffer

Synchronously return a digest generated from the hash function algo and the data in the buffer.

Currently the only supported algorithm is 'SHA-256'.

Direct require

If you only need a single algorithm, you can require that file directly and thus skipping the loading of the other ones. Append a slash followed by the name of the hash function (in lower case without dashes) to the require statement.

Example:

const sha256 = require('crypto-digest-sync/sha256')

const arrayBufferToHex = require('array-buffer-to-hex')
const encodeUtf8 = require('encode-utf8')

const input = encodeUtf8('Hello, World!')
const hash = sha256(input)

console.log(arrayBufferToHex(hash))
//=> dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f

About

Synchronously return a digest generated from the given hash function and data

Resources

Stars

Watchers

Forks

Packages

No packages published