<div id="app">
Nhập chữ cần sử dụng băm:<br>
<input type="text" v-model="input" @input="doHash()"><br>
Kết quả (SHA-256):<br>
{{ result }}
</div>
Vue
// https://bitcoin.stackexchange.com/questions/52727/byte-array-to-hexadecimal-and-back-again-in-javascript
const toHexString = byteArray => {
var bufferView = new Uint8Array(byteArray);
return Array.prototype.map.call(bufferView, function (byte) {
return ("0" + (byte & 0xFF).toString(16)).slice(-2);
}).join("");
};
new Vue({
el: "#app",
data: {
input: null,
result: null
},
methods: {
doHash: async function () {
// Đổi chuỗi đầu vào thành dạng Uint8Array
let inputEncoded = new TextEncoder().encode(this.input);
// Thực hiện tạo chuỗi hash SHA-256
let resultBuffer = await crypto.subtle.digest("SHA-256", inputEncoded);
// Kết quả của resultBuffer là một array buffer.
// Tạo chuỗi và cập nhật vào DOM
this.result = toHexString(resultBuffer);
}
}
})
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.