devicedna
Version:
building your own device fingerprinting library
16 lines (14 loc) • 507 B
JavaScript
export const hashData = (obj) => {
const keys = Object.keys(obj).sort();
const fingerprintString = keys.map(key => `${key}:${obj[key]}`).join('|');
return fingerprintString;
// return djb2Hash(fingerprintString);
};
function djb2Hash(str) {
let hash = 5381;
for (let i = 0; i < str.length; i++) {
hash = ((hash << 5) + hash) + str.charCodeAt(i); // hash * 33 + c
hash = hash & 0xFFFFFFFF; // force 32-bit integer
}
return Math.abs(hash).toString(16); // hex string
}