Skip to content

@technobuddha > library > Binary > Hash

Class: Sha512 ​

Defined in: sha512.ts:158

Secure Hash Algorithm, SHA2 SHA-512

Example ​

typescript
const sha512 = new Sha512();
sha512.update('hello world', 'utf8');
sha512.digest('hex');
// '309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f'
typescript
const sha512 = new Sha512();
sha512.update(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64]));
sha512.digest('hex');
// '309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f'

Extends ​

Constructors ​

Constructor ​

ts
new Sha512(): Sha512;

Defined in: src/sha512.ts:185

Creates a new SHA-512 hash instance and initializes its internal state.

Returns ​

Sha512

Remarks ​

The internal state variables are set to the initial SHA-512 constants as specified in FIPS PUB 180-4. Use update to process data and digest to retrieve the hash.

Overrides ​

ShaBase.constructor

Methods ​

digest() ​

Call Signature ​

ts
digest(): Uint8Array;

Defined in: src/sha-base.ts:77

Finalizes the hash computation and returns the resulting hash digest. This method performs any necessary padding and processes the final block of data according to the hash algorithm's specification.

Returns ​

Uint8Array

The hash digest

Inherited from ​

ShaBase.digest

Call Signature ​

ts
digest(encoding: BinaryEncoding): string;

Defined in: src/sha-base.ts:78

Finalizes the hash computation and returns the resulting hash digest. This method performs any necessary padding and processes the final block of data according to the hash algorithm's specification.

Parameters ​
ParameterTypeDescription
encodingBinaryEncodingOptional. The encoding to use for the output digest (e.g., 'hex', 'base64').
Returns ​

string

An encoded string, depending on the encoding parameter.

Inherited from ​

ShaBase.digest


update() ​

Call Signature ​

ts
update(data: BinaryObject | ArrayLike<number>): this;

Defined in: src/sha-base.ts:119

Updates the hash with the given binary data.

Parameters ​
ParameterTypeDescription
dataBinaryObject | ArrayLike<number>The data to update the hash with, as a BinaryObject.
Returns ​

this

The hash instance for method chaining.

Inherited from ​

ShaBase.update

Call Signature ​

ts
update(data: string, encoding?: TextEncoding): this;

Defined in: src/sha-base.ts:120

Updates the hash with the given string data.

Parameters ​
ParameterTypeDescription
datastringThe string data to update the hash with.
encoding?TextEncodingOptional text encoding of the input string (e.g., 'utf8').
Returns ​

this

The hash instance for method chaining.

Inherited from ​

ShaBase.update