V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
ricky321u
V2EX  ›  JavaScript

把檔案利用 sha256 來計算 hash 值 利用 js 或 node.js

  •  
  •   ricky321u · 2017-10-12 00:08:10 +08:00 · 1783 次点击
    这是一个创建于 2380 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想不到有什麼相關的 library 可以做到,如果是 CryptoJS 可以做到的話也請告知一下 因為我目前只會把 string 換成 hash 希望可以做到新增一個 pdf 或其他檔案 會把其轉成 hASH 值 http://www.atool.org/file_hash.php 感謝各位

    2 条回复    2017-10-16 04:00:41 +08:00
    cctrv
        1
    cctrv  
       2017-10-16 03:56:28 +08:00
    node 走 shell 去獲得 sha256

    Google 兩套關鍵字「 node shell command 」和「 sha256 terminal 」

    https://stackoverflow.com/questions/3358420/generating-a-sha256-from-the-linux-command-line

    https://www.npmjs.com/package/shelljs
    cctrv
        2
    cctrv  
       2017-10-16 04:00:41 +08:00
    或者用這個

    https://www.hacksparrow.com/how-to-generate-md5-sha1-sha512-sha256-checksum-hashes-in-node-js.html

    var crypto = require('crypto');
    var fs = require('fs');

    // change the algo to sha1, sha256 etc according to your requirements
    var algo = 'md5';
    var shasum = crypto.createHash(algo);

    var file = './kitten.jpg';
    var s = fs.ReadStream(file);
    s.on('data', function(d) { shasum.update(d); });
    s.on('end', function() {
    var d = shasum.digest('hex');
    console.log(d);
    });
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3747 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 05:03 · PVG 13:03 · LAX 22:03 · JFK 01:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.