【发布时间】:2017-09-05 01:26:34
【问题描述】:
我正在尝试为文件生成 SHA-256 哈希。
我为此使用了https://www.npmjs.com/package/crypto-js 库。请参阅下面的代码。
import { Component, OnInit } from '@angular/core';
var SHA256 = require("crypto-js/sha256");
@Component({
moduleId: module.id,
selector: 'dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {
hash: string;
constructor() { }
ngOnInit() {}
onFilesChange(fileList : Array<File>){
this.fileList = fileList;
console.log(fileList);
for(var file in fileList){
this.hash = SHA256(file);
console.log(this.hash.toString());
}
}
}
文件:file for sha-256 使用上面的代码,我得到了以下 sh256 哈希:5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
但我参考了许多在线网站,例如http://onlinemd5.com/,http://www.online-convert.com/,https://md5file.com/calculator
形成在线网站,我得到以下 sha256 哈希: 27bb4358e847d559bed9f34eeee51ca71f51542afb0de4017b80dd66a0656eca
谁能告诉我为什么我得到不同的哈希值?
【问题讨论】:
标签: javascript angular sha256 cryptojs