diff --git a/src/hashingAlgoritms.ts b/src/hashingAlgoritms.ts index 314db2a..862adf6 100644 --- a/src/hashingAlgoritms.ts +++ b/src/hashingAlgoritms.ts @@ -11,3 +11,8 @@ export const hashByteLength: Record = { 'SHA-256': 32, 'SHA-512': 64 }; + +export const hashAlgorithmNodeJS: Record = { + 'SHA-256': 'sha256', + 'SHA-512': 'sha512' +}; diff --git a/src/zamane.ts b/src/zamane.ts index 4324fec..6d54840 100644 --- a/src/zamane.ts +++ b/src/zamane.ts @@ -7,7 +7,7 @@ import { TssAdressNotParsableError } from './errors/invalidCredentialsError'; import { createHash } from 'crypto'; -import { hashByteLength, HashingAlgorithm } from './hashingAlgoritms'; +import { hashAlgorithmNodeJS, hashByteLength, HashingAlgorithm } from './hashingAlgoritms'; import { TimeStampRequest } from './TimeStampRequest'; import { tssRequest } from './http_utils'; import { HashLengthError } from './errors/HashLengthError'; @@ -46,7 +46,7 @@ export class Zamane { autoClose: true }); - const hash = createHash(this.hashAlgorithm); + const hash = createHash(hashAlgorithmNodeJS[this.hashAlgorithm]); stream.on('data', (chunk) => { hash.update(chunk); @@ -67,14 +67,14 @@ export class Zamane { } async hashFromContent(content: Buffer): Promise { return new Promise((resolve) => { - const hash = createHash(this.hashAlgorithm); + const hash = createHash(hashAlgorithmNodeJS[this.hashAlgorithm]); hash.update(content); resolve(hash.digest()); }); } async hashFromString(content: string): Promise { return new Promise((resolve) => { - const hash = createHash(this.hashAlgorithm); + const hash = createHash(hashAlgorithmNodeJS[this.hashAlgorithm]); hash.update(content); resolve(hash.digest()); });