diff options
Diffstat (limited to 'prog/ž/gen.html')
-rw-r--r-- | prog/ž/gen.html | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/prog/ž/gen.html b/prog/ž/gen.html new file mode 100644 index 0000000..47fe749 --- /dev/null +++ b/prog/ž/gen.html @@ -0,0 +1,60 @@ +<!DOCTYPE html> +<h1>private</h1> +<canvas id=privkey></canvas> +<div id=privd></div> +<h1>public</h1> +<canvas id=pubkey></canvas> +<div id=pubsec1></div> +<script src=QR-Code-generator/typescript-javascript/qrcodegen.js></script> +<script> +function draw_canvas (qr, scale, border, light, dark, canvas) { + canvas.width = canvas.height = (qr.size + border * 2) * scale; + let ctx = canvas.getContext("2d"); + for (let y = -border; y < qr.size + border; y++) { + for (let x = -border; x < qr.size + border; x++) { + ctx.fillStyle = qr.getModule(x, y) ? dark : light; + ctx.fillRect((x + border) * scale, (y + border) * scale, scale, scale); + } + } +} +function a2hex (a) { + let r = ""; + const hexchars = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]; + for (let i = 0; i < a.length; i++) { + r += hexchars[a[i] >> 4]; + r += hexchars[a[i] % 16]; + } + return r; +} +async function main () { + while (!pubsec1.innerText.startsWith("02aa") && !pubsec1.innerText.startsWith("03aa")) { + window.keyobj = await crypto.subtle.generateKey( + { + name: "ECDSA", + namedCurve: "P-384", + }, + true, + ["sign", "verify"] + ); + let jwk = await crypto.subtle.exportKey("jwk", keyobj.privateKey); + let d = jwk.d.replace(/-/g, "+").replace(/_/g, "/"); + let x = (await crypto.subtle.exportKey("jwk", keyobj.publicKey)).x.replace(/-/g, "+").replace(/_/g, "/"); + let y = (await crypto.subtle.exportKey("jwk", keyobj.publicKey)).y.replace(/-/g, "+").replace(/_/g, "/"); + d = Uint8Array.from(atob(d), c => c.charCodeAt(0)); + privd.innerText = a2hex(d) + "(big endian d) jwk: " + JSON.stringify(jwk); + draw_canvas(qrcodegen.QrCode.encodeText(JSON.stringify(jwk), qrcodegen.QrCode.Ecc.LOW), 5, 4, "#FFF", "#000", privkey); + x = Uint8Array.from(atob(x), c => c.charCodeAt(0)); + y = Uint8Array.from(atob(y), c => c.charCodeAt(0)); + var sec1 = new Uint8Array(49); + if (y[47] % 2) + sec1[0] = 3; + else + sec1[0] = 2; + for (let i = 0; i < 48; i++) + sec1[1+i] = x[i]; + pubsec1.innerText = a2hex(sec1) + " (sec-1)"; + draw_canvas(qrcodegen.QrCode.encodeBinary(sec1, qrcodegen.QrCode.Ecc.LOW), 10, 4, "#FFF", "#000", pubkey); + } +} +main(); +</script> |