diff --git a/src/services/crypto.service.ts b/src/services/crypto.service.ts index 93dbcd3b5c..243afb66aa 100644 --- a/src/services/crypto.service.ts +++ b/src/services/crypto.service.ts @@ -453,13 +453,8 @@ export class CryptoService implements CryptoServiceAbstraction { } async sha1(password: string): Promise { - const hash = await Crypto.subtle.digest( - { - name: 'SHA-1', - }, - UtilsService.fromUtf8ToArray(password), - ); - + const passwordArr = UtilsService.fromUtf8ToArray(password); + const hash = await Crypto.subtle.digest({ name: 'SHA-1' }, passwordArr); return UtilsService.fromBufferToHex(hash); } diff --git a/src/services/utils.service.ts b/src/services/utils.service.ts index a1e900e761..7f692ae191 100644 --- a/src/services/utils.service.ts +++ b/src/services/utils.service.ts @@ -125,12 +125,10 @@ export class UtilsService implements UtilsServiceAbstraction { return decodeURIComponent(escape(encodedString)); } - // Source: Frxstrem, https://stackoverflow.com/questions/40031688/javascript-arraybuffer-to-hex + // ref: https://stackoverflow.com/a/40031979/1090359 static fromBufferToHex(buffer: ArrayBuffer): string { - return Array.prototype.map.call( - new Uint8Array(buffer), - (x: number) => ('00' + x.toString(16)).slice(-2), - ).join(''); + const bytes = new Uint8Array(buffer); + return Array.prototype.map.call(bytes, (x: number) => ('00' + x.toString(16)).slice(-2)).join(''); } static getHostname(uriString: string): string {