Skip to content

Instantly share code, notes, and snippets.

@Gaubee
Last active February 5, 2020 16:23
Show Gist options
  • Save Gaubee/76dd572ee2746208eebcbffd191e02ab to your computer and use it in GitHub Desktop.
Save Gaubee/76dd572ee2746208eebcbffd191e02ab to your computer and use it in GitHub Desktop.
取代cookie的网站追踪技术:”帆布指纹识别”初探
function bin2hex (bin)
{
var i = 0, l = bin.length, chr, hex = '';
for (i; i < l; ++i)
{
chr = bin.charCodeAt(i).toString(16)
hex += chr.length < 2 ? '0' + chr : chr
}
return hex
}
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
var txt = 'http://security.tencent.com/';
ctx.textBaseline = "top";
ctx.font = "14px 'Arial'";
ctx.textBaseline = "tencent";
ctx.fillStyle = "#f60";
ctx.fillRect(125,1,62,20);
ctx.fillStyle = "#069";
ctx.fillText(txt, 2, 15);
ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
ctx.fillText(txt, 4, 17);
var b64 = canvas.toDataURL().replace("data:image/png;base64,","");
var bin = atob(b64);
var crc = bin2hex(bin.slice(-16,-12));
console.log(crc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment