jsencrypt
jsencrypt copied to clipboard
Problem after upgrade to latest version from 3.2.1 on verify method
trafficstars
Hello, I'm in the middle of an Angular update version from 9 to 16 and I'm getting this error when I updated crypto-js from 3.2.1 to 3.3.2
The original code was
verifySignature(payload: string, signature: string, key: string): boolean {
this.crypto.setPublicKey(key);
const result = this.crypto.verify(payload, signature,CryptoJS.SHA256);
return result;
}
but It was giving this error
Error: src/app/shared/services/crypto.service.ts:47:59 - error TS2345: Argument of type 'HasherHelper' is not assignable to parameter of type '(str: string) => string'. Type 'WordArray' is not assignable to type 'string'.
47 const result = this.crypto.verify(payload, signature, CryptoJS.SHA256);
Is this enough to replace the code with
verifySignature(payload: string, signature: string, key: string): boolean {
this.crypto.setPublicKey(key);
const result = this.crypto.verify(payload, signature,(_)=> CryptoJS.SHA256.name);
return result;
}
or is there a correct and better way? At the moment I cannot create a unit test for this since the solution is not compiling
Any help appreciated, Thanks