温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/crypto/hash
点击访问原文链接

Node crypto.hash function | API Reference | Bun

Node crypto.hash function | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/node:crypto/hashFhash

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:crypto/hashFhash

function

crypto.hash console.log(crypto.hash('sha1', Buffer.from(base64, 'base64'), 'buffer')); ```" data-algolia-static="false" data-algolia-merged="false" data-type="Function">function hash(algorithm: string,data: BinaryLike,options?: BinaryToTextEncoding | OneShotDigestOptionsWithStringEncoding): string;

A utility for creating one-shot hash digests of data. It can be faster than the object-based crypto.createHash() when hashing a smaller amount of data (crypto.createHash() instead.

The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha256', 'sha512', etc. On recent releases of OpenSSL, openssl list -digest-algorithms will display the available digest algorithms.

If options is a string, then it specifies the outputEncoding.

Example:

import crypto from 'node:crypto';
import { Buffer } from 'node:buffer';

// Hashing a string and return the result as a hex-encoded string.
const string = 'Node.js';
// 10b3493287f831e81a438811a1ffba01f8cec4b7
console.log(crypto.hash('sha1', string));

// Encode a base64-encoded string into a Buffer, hash it and return
// the result as a buffer.
const base64 = 'Tm9kZS5qcw==';
//
console.log(crypto.hash('sha1', Buffer.from(base64, 'base64'), 'buffer'));
@param data

When data is a string, it will be encoded as UTF-8 before being hashed. If a different input encoding is desired for a string input, user could encode the string into a TypedArray using either TextEncoder or Buffer.from() and passing the encoded TypedArray into this API instead.

function hash(algorithm: string,data: BinaryLike,options: 'buffer' | OneShotDigestOptionsWithBufferEncoding): NonSharedBuffer;

A utility for creating one-shot hash digests of data. It can be faster than the object-based crypto.createHash() when hashing a smaller amount of data (crypto.createHash() instead.

The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha256', 'sha512', etc. On recent releases of OpenSSL, openssl list -digest-algorithms will display the available digest algorithms.

If options is a string, then it specifies the outputEncoding.

Example:

import crypto from 'node:crypto';
import { Buffer } from 'node:buffer';

// Hashing a string and return the result as a hex-encoded string.
const string = 'Node.js';
// 10b3493287f831e81a438811a1ffba01f8cec4b7
console.log(crypto.hash('sha1', string));

// Encode a base64-encoded string into a Buffer, hash it and return
// the result as a buffer.
const base64 = 'Tm9kZS5qcw==';
//
console.log(crypto.hash('sha1', Buffer.from(base64, 'base64'), 'buffer'));
@param data

When data is a string, it will be encoded as UTF-8 before being hashed. If a different input encoding is desired for a string input, user could encode the string into a TypedArray using either TextEncoder or Buffer.from() and passing the encoded TypedArray into this API instead.

function hash(algorithm: string,data: BinaryLike,options: 'buffer' | BinaryToTextEncoding | OneShotDigestOptions): string | NonSharedBuffer;

A utility for creating one-shot hash digests of data. It can be faster than the object-based crypto.createHash() when hashing a smaller amount of data (crypto.createHash() instead.

The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha256', 'sha512', etc. On recent releases of OpenSSL, openssl list -digest-algorithms will display the available digest algorithms.

If options is a string, then it specifies the outputEncoding.

Example:

import crypto from 'node:crypto';
import { Buffer } from 'node:buffer';

// Hashing a string and return the result as a hex-encoded string.
const string = 'Node.js';
// 10b3493287f831e81a438811a1ffba01f8cec4b7
console.log(crypto.hash('sha1', string));

// Encode a base64-encoded string into a Buffer, hash it and return
// the result as a buffer.
const base64 = 'Tm9kZS5qcw==';
//
console.log(crypto.hash('sha1', Buffer.from(base64, 'base64'), 'buffer'));
@param data

When data is a string, it will be encoded as UTF-8 before being hashed. If a different input encoding is desired for a string input, user could encode the string into a TypedArray using either TextEncoder or Buffer.from() and passing the encoded TypedArray into this API instead.

Referenced typestype BinaryLike = string | NodeJS.ArrayBufferViewtype BinaryToTextEncoding = 'base64' | 'base64url' | 'hex' | 'binary'interface OneShotDigestOptionsWithStringEncodingoutputEncoding?: BinaryToTextEncoding

Encoding used to encode the returned digest.

outputLength?: number

For XOF hash functions such as 'shake256', the outputLength option can be used to specify the desired output length in bytes.

interface OneShotDigestOptionsWithBufferEncodingoutputEncoding: 'buffer'

Encoding used to encode the returned digest.

outputLength?: number

For XOF hash functions such as 'shake256', the outputLength option can be used to specify the desired output length in bytes.

interface OneShotDigestOptionsoutputEncoding?: 'buffer' | BinaryToTextEncoding

Encoding used to encode the returned digest.

outputLength?: number

For XOF hash functions such as 'shake256', the outputLength option can be used to specify the desired output length in bytes.

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Node crypto.hash function | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for function node:crypto.hash | Bun