Skip to content
المشاريع

حول

وحدة صغيرة للتجزئة تستخدم واجهة التشفير الأصلية في Node.js والمتصفح.

أدوات التطوير

كيف تُقاس هذه الأرقام

النمو المقاس للنجوم

خلال 24 ساعة
٠
خلال 7 أيام
٠
خلال 15 يومًا
٠
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

crypto-hash

Tiny hashing module that uses the native crypto API in Node.js and the browser

Useful when you want the same hashing API in all environments. My cat calls it isomorphic.

In Node.js it uses node:crypto, while in the browser it uses window.crypto.

The browser version is about 650 bytes minified & gzipped.

When used in the browser, it must be in a secure context (HTTPS).

This package is for modern browsers. Internet Explorer is not supported.

Install

npm install crypto-hash

Usage

import {sha256} from 'crypto-hash';

console.log(await sha256('🦄'));
//=> '36bf255468003165652fe978eaaa8898e191664028475f83f506dabd95298efc'

const digest = await sha256('🦄', {outputFormat: 'buffer'});
//=> ArrayBuffer (32 bytes)

API

sha1(input, options?)

sha256(input, options?)

sha384(input, options?)

sha512(input, options?)

Returns a Promise<string> with a Hex-encoded hash.

In Node.js, the operation is executed using worker_threads. A thread is lazily spawned on the first operation and reused from then on; if it ever exits, the next operation spawns a replacement. It is unrefed while no operation is in flight, so it will not keep the process alive.

SHA-1 is insecure and should not be used for anything sensitive.

input

Type: string ArrayBuffer SharedArrayBuffer ArrayBufferView

The input is always copied, so the buffer you pass in is never detached, and a view hashes only the range it covers. Anything else, including a detached buffer, rejects with a TypeError.

options

Type: object

outputFormat

Type: string
Values: 'hex' | 'buffer'
Default: 'hex'

Setting this to buffer makes it return an ArrayBuffer instead of a string. Any other value rejects with a TypeError rather than quietly returning one or the other.

Related

  • hasha - Hashing in Node.js made simple

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…