[英]SHA256 is undefined
I was experimenting with CryptoJS library and came across with the problem that my imported hash function isn't visible inside a class. 我在尝试使用CryptoJS库时遇到了这样的问题:导入的哈希函数在类中不可见。 Here's my code:
这是我的代码:
CryptoJS = require('crypto-js');
SHA256 = require('crypto-js/sha256');
class trCrypt {
constructor(input,key) {
this.input = input;
this.key = SHA512(key).toString();
}
encrypt(){
this.step1 = CryptoJS.AES.encrypt(this.input,this.key);
return this.step1.toString()
}
decrypt(){
const bytes = CryptoJS.AES.decrypt(this.step1);
this.dec1 = bytes.toString(CryptoJS.enc.Utf8);
return this.dec1
}
}
a = new trCrypt('hello','world');
console.log(a.encrypt());
console.log(a.decrypt());
[SOLVED] Thanks for answer! [已解决]谢谢您的回答!
In your code you've imported the CryptoJs module and the SHA256 function, but you've not imported the SHA512 function. 在代码中,您已经导入了CryptoJs模块和SHA256函数,但是尚未导入SHA512函数。
Try adding: 尝试添加:
SHA512 = require('crypto-js/sha512');
On top of the script 在脚本之上
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.