@@ -127,8 +127,8 @@ <h3 id="methods">
127
127
128
128
< tr >
129
129
< td class ="col-md-4 ">
130
- < div class ="io-line "> Defined in < a href ="" data-line ="16 "
131
- class ="link-to-prism "> projects/lib/src/token-validation/hash-handler.ts:16 </ a > </ div >
130
+ < div class ="io-line "> Defined in < a href ="" data-line ="33 "
131
+ class ="link-to-prism "> projects/lib/src/token-validation/hash-handler.ts:33 </ a > </ div >
132
132
</ td >
133
133
</ tr >
134
134
@@ -207,8 +207,8 @@ <h3 id="methods">
207
207
208
208
< tr >
209
209
< td class ="col-md-4 ">
210
- < div class ="io-line "> Defined in < a href ="" data-line ="36 "
211
- class ="link-to-prism "> projects/lib/src/token-validation/hash-handler.ts:36 </ a > </ div >
210
+ < div class ="io-line "> Defined in < a href ="" data-line ="60 "
211
+ class ="link-to-prism "> projects/lib/src/token-validation/hash-handler.ts:60 </ a > </ div >
212
212
</ td >
213
213
</ tr >
214
214
@@ -275,8 +275,8 @@ <h3 id="methods">
275
275
276
276
< tr >
277
277
< td class ="col-md-4 ">
278
- < div class ="io-line "> Defined in < a href ="" data-line ="28 "
279
- class ="link-to-prism "> projects/lib/src/token-validation/hash-handler.ts:28 </ a > </ div >
278
+ < div class ="io-line "> Defined in < a href ="" data-line ="52 "
279
+ class ="link-to-prism "> projects/lib/src/token-validation/hash-handler.ts:52 </ a > </ div >
280
280
</ td >
281
281
</ tr >
282
282
@@ -332,28 +332,52 @@ <h3 id="methods">
332
332
< pre class ="line-numbers compodoc-sourcecode "> < code class ="language-typescript "> import { Injectable } from '@angular/core';
333
333
334
334
import { factory } from './js-sha256';
335
-
336
335
const sha256 = factory();
337
336
337
+ import fsha256 from 'fast-sha256';
338
+
338
339
/**
339
340
* Abstraction for crypto algorithms
340
341
*/
341
342
export abstract class HashHandler {
342
343
abstract calcHash(valueToHash: string, algorithm: string): Promise<string>;
343
344
}
344
345
346
+ function decodeUTF8(s) {
347
+ if (typeof s !== 'string') throw new TypeError('expected string');
348
+ var i,
349
+ d = s,
350
+ b = new Uint8Array(d.length);
351
+ for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i);
352
+ return b;
353
+ }
354
+
355
+ function encodeUTF8(arr) {
356
+ var i,
357
+ s = [];
358
+ for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i]));
359
+ return s.join('');
360
+ }
361
+
345
362
@Injectable()
346
363
export class DefaultHashHandler implements HashHandler {
347
364
async calcHash(valueToHash: string, algorithm: string): Promise<string> {
348
365
// const encoder = new TextEncoder();
349
366
// const hashArray = await window.crypto.subtle.digest(algorithm, data);
350
367
// const data = encoder.encode(valueToHash);
351
368
352
- const hashArray = (sha256 as any).array(valueToHash);
353
- // const hashString = this.toHashString(hashArray);
354
- const hashString = this.toHashString2(hashArray);
369
+ // const fhash = fsha256(valueToHash);
370
+
371
+ const candHash = encodeUTF8(fsha256(decodeUTF8(valueToHash)));
372
+
373
+ // const hashArray = (sha256 as any).array(valueToHash);
374
+ // // const hashString = this.toHashString(hashArray);
375
+ // const hashString = this.toHashString2(hashArray);
376
+
377
+ // console.debug('hash orig - cand', candHash, hashString);
378
+ // alert(1);
355
379
356
- return hashString ;
380
+ return candHash ;
357
381
}
358
382
359
383
toHashString2(byteArray: number[]) {
0 commit comments