0

Verify a license key

by
Published Jan 15, 2023

Verify a license key generated by https://hub.windmill.dev/scripts/helper/1508/generate-a-license-key-using-rsa-pss-for-a-customer-helper

Script helper
Other submissions
  • Submitted by admin Deno
    Created 1255 days ago
    1
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    2
    
    
    3
    // licenseKey generated by https://hub.windmill.dev/scripts/helper/1508/generate-a-license-key-using-rsa-pss-for-a-customer-helper
    4
    export async function main(licenseKey: string) {
    5
      const [client, signature] = licenseKey.split('.')
    6
      const data = new TextEncoder().encode(atob(client))
    7
      const signatureAb = Uint8Array.from(atob(signature), c => c.charCodeAt(0))
    8
    
    
    9
      // publicKey generated by https://hub.windmill.dev/scripts/helper/1509/generate-an-rsa-pss-key-pair-helper
    10
      let publicKey = await importPublicKey(
    11
        (await wmill.getVariable("u/user/public_license_key"))!,
    12
      );
    13
      let verified = await crypto.subtle.verify(
    14
        {
    15
          name: "RSA-PSS",
    16
          saltLength: 32,
    17
        },
    18
        publicKey,
    19
        signatureAb,
    20
        data
    21
      );
    22
    
    
    23
      return verified;
    24
    }
    25
    
    
    26
    function importPublicKey(pem: string) {
    27
      const binaryDerString = window.atob(pem);
    28
      const binaryDer = str2ab(binaryDerString);
    29
    
    
    30
      return window.crypto.subtle.importKey(
    31
        "spki",
    32
        binaryDer,
    33
        {
    34
          name: "RSA-PSS",
    35
          hash: "SHA-256",
    36
        },
    37
        true,
    38
        ["verify"],
    39
      );
    40
    }
    41
    
    
    42
    function str2ab(str: string) {
    43
      const buf = new ArrayBuffer(str.length);
    44
      const bufView = new Uint8Array(buf);
    45
      for (let i = 0, strLen = str.length; i < strLen; i++) {
    46
        bufView[i] = str.charCodeAt(i);
    47
      }
    48
      return buf;
    49
    }
    50
    
    
  • Submitted by leon03ishim268 Bun
    Created 497 days ago
    1
    https://keyguardian.org/a/1308?id=da05ef6e57d84a78b7c6411702449ffd
    2