Using SHA-256 with NodeJS Crypto

前端 未结 3 1393
忘了有多久
忘了有多久 2021-02-04 23:46

I\'m trying to hash a variable in NodeJS like so:

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

var hash = crypto.createHash(\'sha256\');

var code = \'bacon\';

code = has         


        
3条回答
  •  生来不讨喜
    2021-02-05 00:16

    nodejs (8) ref

    const crypto = require('crypto');
    const hash = crypto.createHash('sha256');
    
    hash.on('readable', () => {
        const data = hash.read();
        if (data) {
            console.log(data.toString('hex'));
            // Prints:
            //  6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
        }
    });
    
    hash.write('some data to hash');
    hash.end();
    

提交回复
热议问题