window.crypto.subtle.digest(
{
name: "SHA-256",
},
imageFileData // The image file data you want to calculate a hash for as an ArrayBuffer
)
.then(function(hash) {
// convert the hash to byte array
const hashArray = Array.from(new Uint8Array(hash));
// convert bytes to hex string
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
// use the hashHex string for comparison
})
.catch(function(err) {
console.error(err);
});
1条答案
按热度按时间arknldoa1#
您可以使用WebCrypto API来计算SHA-256哈希。
字符串