[英]SHA256 is undefined
我在尝试使用CryptoJS库时遇到了这样的问题:导入的哈希函数在类中不可见。 这是我的代码:
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());
[已解决]谢谢您的回答!
在代码中,您已经导入了CryptoJs模块和SHA256函数,但是尚未导入SHA512函数。
尝试添加:
SHA512 = require('crypto-js/sha512');
在脚本之上
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.