查看下载文件的sha512

  1. 本地文件查看

Get-FileHash -Algorithm SHA512 D:\Desktop\project\dcircle-pc-client\renderer\Dcircle_Setup_0.9.0.exe
2.线上地址文件查看

const fileUrl = 'https://dcircle-dev.oss-cn-hongkong.aliyuncs.com/configs/yml/Dcircle_Setup_0.9.0.exe';
    const localFilePath = 'Dcircle_Setup_0.9.0.exe';

    axios({
      method: 'get',
      url: fileUrl,
      responseType: 'stream',
    }).then(response => {
      const writer = fs.createWriteStream(localFilePath);
      response.data.pipe(writer);

      writer.on('finish', () => {
        console.log('文件下载完成');
        // 在下载完成后计算SHA-512哈希值
        calculateSHA512Hash(localFilePath);
      });

      writer.on('error', err => {
        console.error('下载失败', err);
      });
    });
    function calculateSHA512Hash(filePath) {
      const sha512Hash = crypto.createHash('sha512');
      const fileStream = fs.createReadStream(filePath);

      fileStream.on('data', data => {
        sha512Hash.update(data);
      });

      fileStream.on('end', () => {
        const hashValue = sha512Hash.digest('hex');
        // mainWindow.webContents.executeJavaScript(`console.log('文件的SHA-512哈希值:', ${hashValue})`)
        console.log('文件的SHA-512哈希值:', hashValue);
      });

      fileStream.on('error', err => {
        console.error('计算哈希值失败', err);
      });
    }

你可能感兴趣的:(哈希算法,算法,javascript,react.js)