I want to hash a base64 to a base16 and put the result into a kvp array. Here my code (the base64 used here is hypothetical, it's to show you the problem) :
async function hashData() {
let base64 = 'sertyuiopnbv58426931';
let hash = await window.crypto.subtle.digest('SHA-256', _base64ToArrayBuffer(base64));
const hashArray = Array.from(new Uint8Array(hash));
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
console.log(hashHex);
return hashHex;
}
function _base64ToArrayBuffer(mybase64) {
let binary_string = window.atob(mybase64);
let len = binary_string.length;
let bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
}
function GetClubData () {
let kvp = {};
kvp['picture'] = hashData();
let kvp2 = {};
kvp2['Club'] = kvp;
var json = JSON.stringify(kvp2,null," ");
console.log(json);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title> Test </title>
<link rel="stylesheet" href="test1.css"/>
</head>
<body>
<button onclick="GetClubData()" > Get Club Data </button>
<script src="../mylibrary/js/updateClub.js"></script>
</body>
In my console there is no 'picture' result. Any idea ?
