I've been getting an error while using Crypto.js and couldn't figure out why. I tried to use the createHash.update.digest methods. After some time I realized that I had a typo but the error that have been thrown was incorrect. the error was:
"digest method cant be used"
My code was:
this.passwordResetToken = crypto.createHash('sh256').update(resetToken).digest('hex');
The solution to the error was changing the createHash algorithm to the currect one without the typo:
this.passwordResetToken = crypto.createHash('sha256').update(resetToken).digest('hex');
I had a missing 'a' in the algorithm name. Why is the error saying "digest method cant be used" when I have made a typo?
CodePudding user response:
The reason for the behavior you experienced is that the parameter specified for createHash
specifies the digest method. Since you have provided an invalid digest method (because of your typo), the tool checked whether that digest method is available and found that it is not, hence you received this error.