前端的crypto-js库跟node版本的crypto不一样,前者只是实现了部分功能,crypto-js对二进制流加密时有大小限制,超长了会报错。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="file" id="cc">
</body>
</html>
<script src="node_modules/crypto-js/crypto-js.js"></script>
<script>
console.log(CryptoJS);
var cc = document.getElementById('cc');
cc.addEventListener('change',function(e){
console.log(e.target.files[0]);
let file = e.target.files[0];
var fr = new FileReader();
fr.readAsBinaryString(file);
fr.onload = function(){
let res = fr.result;
let code = CryptoJS.SHA512(res);
console.log(code.toString());
}
});
</script>
网友评论