所以我尝试从文件中获取哈希。使用CryptoSwift库。这truth
是我从 VLC 网站获得的带有哈希值的变量,所以这应该是真的。但是,我生成的散列与我知道的真实散列不同。
我错过了哪一步?
代码:
let filePath = "/Users/pjc/Desktop/vlc-3.0.0.dmg"
let fileURL = URL(fileURLWithPath: filePath)
let truth = "e6f7179cb06809b6101803da3ac4191edb72ecf82f31b8ae7dbf010e1a78ba26"
do {
let fileData = try Data.init(contentsOf: fileURL)
print(fileData)
let fileBytes = fileData.bytes
let hash = fileBytes.sha256()
print(hash.debugDescription)
} catch {
//handle error
print(error)
}
print(hash)
print(truth)
日志:
fileData: 46818658 bytes
hash.debugDescription: [230, 247, 23, 156, 176, 104, 9, 182, 16, 24, 3, 218, 58, 196, 25, 30, 219, 114, 236, 248, 47, 49, 184, 174, 125, 191, 1, 14, 26, 120, 186, 38]
hash: 105553117580736
truth: e6f7179cb06809b6101803da3ac4191edb72ecf82f31b8ae7dbf010e1a78ba26