blob: 826c8eed93b85e6d1a9c787f56be8eb867225de5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
String.prototype.getHash = async function() {
let data = new ArrayBuffer(this.length * 2);
let bufferView = new Uint16Array(data);
for (let i = 0; i < this.length; i++) {
bufferView[i] = this.charCodeAt(i);
}
let encrypted = await crypto.subtle.digest('SHA-256', bufferView);
let byteArray = new Uint8Array(encrypted);
let base64String = '';
for (let byte of byteArray) {
base64String += String.fromCharCode(byte);
}
return btoa(base64String);
}
|