对此我是陌生的,但我的要求是我想使用Node.js加密模块来使用20个字符长的加密密钥。
我尝试过但无法获得固定长度的密钥。
任何人都可以帮助我。
谢谢。
答案 0 :(得分:0)
您可以使用crypto.randomBytes生成密钥,例如:
componentDidMount() {
fetch("https://api.myjson.com/bins/1ep1fh")
.then(res => res.json())
.then(result => {
let texts = result
.map((el, i) => {
return el.text;
})
.join("");
let highlights = result
.map((el, i) => {
return el.highlight;
})
.join("").split(",");
console.log(highlights);
this.setState({
text: texts,
highlight: highlights
});
});
}
您还可以使用crypto.scrypt函数从较长的密码短语中得出固定长度的密钥:
const crypto = require('crypto');
const key = crypto.randomBytes(10).toString('hex');
console.log(`key: ${key} length: ${key.length}`);