我的代码如下所示:
let createCipher = (req, res) => {
const text = req.body.text;
let hash = crypto.createHash('md5').update(utf8.encode(text)).digest('hex');
res.json({
status: '200',
data: hash,
utf: utf8.encode(text)
});
}
在这里,无论我提供什么 text 输入参数,都会在响应字段 utf 中返回。所以utf8进程中有什么缺失吗?
答案 0 :(得分:1)
let createCipher = (req, res) => {
const text = req.body.text;
//text = "Hello World";
let hash = crypto.createHash('md5');
hash.update(utf8.encode(text));
//or you try
//let hash = crypto.createHash('md5').update(utf8.encode(text));
let data = hash.digest('hex');
//console.log(data + ' ' + text);
//console.log("utf8 - byte data : " + utf8.encode(data)+ ' ' + utf8.encode(text));
res.json({
status: '200',
data: hash,
utf: utf8.encode(data) //data
});
}
//Output
//b10a8db164e0754105b7a99be72e3fe5 Hello World
//utf8 - byte data : b10a8db164e0754105b7a99be72e3fe5 Hello World