-4

I have a script in python that takes a salt and returns proof using sha256.

I do not know very much about javascript, or about any of the libraries.

import sys
from hashlib import sha256

def generate_proof(salt):
    secret_salt =  SECRET + salt
    hexadecimal = secret_salt.decode('hex')
    proof = sha256(hexadecimal).hexdigest()
    return proof

Could someone please translate or explain how I can translate this method into javascript?

I think my biggest problem is finding the sha256 equivalent library in JS.

meeky333
  • 5
  • 1
  • Possible duplicate of [I have to Hash a text with HMAC sha256 in Javascript](https://stackoverflow.com/questions/49081874/i-have-to-hash-a-text-with-hmac-sha256-in-javascript) – Phu Ngo Jul 12 '19 at 08:56

1 Answers1

0
//  node.js
const filename = process.argv[2];
const crypto = require('crypto');
const fs = require('fs');

const hash = crypto.createHash('sha256');

const input = fs.createReadStream(filename);
input.on('readable', () => {
  // Only one element is going to be produced by the
  // hash stream.
  const data = input.read();
  if (data)
    hash.update(data);
  else {
    console.log(`${hash.digest('hex')} ${filename}`);
  }
});
dbzsh
  • 12