Edits history of script submission #278 for ' Generate a license key using RSA PSS for a customer (helper)'

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    
    export async function main(client: string) {
      const encoded = new TextEncoder().encode(client);
    
      // key generated by https://hub.windmill.dev/scripts/helper/1509/generate-an-rsa-pss-key-pair-helper
      let privateKey = await importPrivateKey(
        (await wmill.getVariable("u/user/your_private_key"))!,
      );
      let signature = await crypto.subtle.sign(
        {
          name: "RSA-PSS",
          saltLength: 32,
        },
        privateKey,
        encoded,
      );
    
      // Combine the encoded data and signature to create a license key
      const licenseKey = `${btoa(client)}.${abToBase64(signature)}`;
    
      return licenseKey;
    }
    
    function abToBase64(arrayBuffer: ArrayBuffer) {
      return btoa(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer)));
    }
    
    function importPrivateKey(pem: string) {
      const binaryDerString = window.atob(pem);
      const binaryDer = str2ab(binaryDerString);
    
      return window.crypto.subtle.importKey(
        "pkcs8",
        binaryDer,
        {
          name: "RSA-PSS",
          hash: "SHA-256",
        },
        true,
        ["sign"],
      );
    }
    
    function str2ab(str: string) {
      const buf = new ArrayBuffer(str.length);
      const bufView = new Uint8Array(buf);
      for (let i = 0, strLen = str.length; i < strLen; i++) {
        bufView[i] = str.charCodeAt(i);
      }
      return buf;
    }
    

    Submitted by hugo697 399 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    
    export async function main(client: string) {
      const encoded = new TextEncoder().encode(client);
    
      // key generated by https://hub.windmill.dev/scripts/helper/1509/generate-an-rsa-pss-key-pair-helper
      let privateKey = await importPrivateKey(
        (await wmill.getVariable("u/user/your_private_key"))!,
      );
      let signature = await crypto.subtle.sign(
        {
          name: "RSA-PSS",
          saltLength: 32,
        },
        privateKey,
        encoded,
      );
    
      // Combine the encoded data and signature to create a license key
      const licenseKey = `${btoa(client)}.${abToBase64(signature)}`;
    
      return licenseKey;
    }
    
    function abToBase64(arrayBuffer: ArrayBuffer) {
      return btoa(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer)));
    }
    
    function importPrivateKey(pem: string) {
      const binaryDerString = window.atob(pem);
      const binaryDer = str2ab(binaryDerString);
    
      return window.crypto.subtle.importKey(
        "pkcs8",
        binaryDer,
        {
          name: "RSA-PSS",
          hash: "SHA-256",
        },
        true,
        ["sign"],
      );
    }
    
    function str2ab(str: string) {
      const buf = new ArrayBuffer(str.length);
      const bufView = new Uint8Array(buf);
      for (let i = 0, strLen = str.length; i < strLen; i++) {
        bufView[i] = str.charCodeAt(i);
      }
      return buf;
    }
    

    Submitted by admin 1031 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    
    export async function main(client: string) {
      const encoded = new TextEncoder().encode(client);
    
      // key generated by https://hub.windmill.dev/scripts/helper/1509/generate-an-rsa-pss-key-pair-helper
      let privateKey = await importPrivateKey(
        (await wmill.getVariable("u/user/your_private_key"))!,
      );
      let signature = await crypto.subtle.sign(
        {
          name: "RSA-PSS",
          saltLength: 32,
        },
        privateKey,
        encoded,
      );
    
      // Combine the encoded data and signature to create a license key
      const licenseKey = `${btoa(client)}.${abToBase64(signature)}`;
    
      return licenseKey;
    }
    
    function abToBase64(arrayBuffer: ArrayBuffer) {
      return btoa(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer)))
    }
    
    function importPrivateKey(pem: string) {
      const binaryDerString = window.atob(pem);
      const binaryDer = str2ab(binaryDerString);
    
      return window.crypto.subtle.importKey(
        "pkcs8",
        binaryDer,
        {
          name: "RSA-PSS",
          hash: "SHA-256",
        },
        true,
        ["sign"],
      );
    }
    
    function str2ab(str: string) {
      const buf = new ArrayBuffer(str.length);
      const bufView = new Uint8Array(buf);
      for (let i = 0, strLen = str.length; i < strLen; i++) {
        bufView[i] = str.charCodeAt(i);
      }
      return buf;
    }
    

    Submitted by adam186 1163 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    
    export async function main(client: string) {
      const encoded = new TextEncoder().encode(client);
    
      // key generated by https://hub.windmill.dev/scripts/helper/1509/generate-an-rsa-pss-key-pair-helper
      let privateKey = await importPrivateKey(
        (await wmill.getVariable("u/user/your_private_key"))!,
      );
      let signature = await crypto.subtle.sign(
        {
          name: "RSA-PSS",
          saltLength: 32,
        },
        privateKey,
        encoded,
      );
    
      // Combine the encoded data and signature to create a license key
      const licenseKey = `${btoa(client)}.${abToBase64(signature)}`;
    
      return licenseKey;
    }
    
    function abToBase64(arrayBuffer: ArrayBuffer) {
      return btoa(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer)))
    }
    
    function importPrivateKey(pem: string) {
      const binaryDerString = window.atob(pem);
      const binaryDer = str2ab(binaryDerString);
    
      return window.crypto.subtle.importKey(
        "pkcs8",
        binaryDer,
        {
          name: "RSA-PSS",
          hash: "SHA-256",
        },
        true,
        ["sign"],
      );
    }
    
    function str2ab(str: string) {
      const buf = new ArrayBuffer(str.length);
      const bufView = new Uint8Array(buf);
      for (let i = 0, strLen = str.length; i < strLen; i++) {
        bufView[i] = str.charCodeAt(i);
      }
      return buf;
    }
    

    Submitted by adam186 1198 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    
    export async function main(client: string) {
      const encoded = new TextEncoder().encode(client);
    
      // key generated by https://hub.windmill.dev/scripts/helper/1509/generate-an-rsa-pss-key-pair-helper
      let privateKey = await importPrivateKey(
        (await wmill.getVariable("u/user/your_private_key"))!,
      );
      let signature = await crypto.subtle.sign(
        {
          name: "RSA-PSS",
          saltLength: 32,
        },
        privateKey,
        encoded,
      );
    
      // Combine the encoded data and signature to create a license key
      const licenseKey = `${btoa(client)}.${abToBase64(signature)}`;
    
      return licenseKey;
    }
    
    function abToBase64(arrayBuffer: ArrayBuffer) {
      return btoa(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer)))
    }
    
    function importPrivateKey(pem: string) {
      const binaryDerString = window.atob(pem);
      const binaryDer = str2ab(binaryDerString);
    
      return window.crypto.subtle.importKey(
        "pkcs8",
        binaryDer,
        {
          name: "RSA-PSS",
          hash: "SHA-256",
        },
        true,
        ["sign"],
      );
    }
    
    function str2ab(str: string) {
      const buf = new ArrayBuffer(str.length);
      const bufView = new Uint8Array(buf);
      for (let i = 0, strLen = str.length; i < strLen; i++) {
        bufView[i] = str.charCodeAt(i);
      }
      return buf;
    }
    

    Submitted by admin 1242 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    
    export async function main(client: string) {
      const encoded = new TextEncoder().encode(client);
    
      // key generated by https://hub.windmill.dev/scripts/helper/1507/generate-an-rsa-key-pair-helper
      let privateKey = await importPrivateKey(
        (await wmill.getVariable("u/user/your_private_key"))!,
      );
      let signature = await crypto.subtle.sign(
        {
          name: "RSA-PSS",
          saltLength: 32,
        },
        privateKey,
        encoded,
      );
    
      // Combine the encoded data and signature to create a license key
      const licenseKey = `${btoa(client)}.${abToBase64(signature)}`;
    
      return licenseKey;
    }
    
    function abToBase64(arrayBuffer: ArrayBuffer) {
      return btoa(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer)))
    }
    
    function importPrivateKey(pem: string) {
      const binaryDerString = window.atob(pem);
      const binaryDer = str2ab(binaryDerString);
    
      return window.crypto.subtle.importKey(
        "pkcs8",
        binaryDer,
        {
          name: "RSA-PSS",
          hash: "SHA-256",
        },
        true,
        ["sign"],
      );
    }
    
    function str2ab(str: string) {
      const buf = new ArrayBuffer(str.length);
      const bufView = new Uint8Array(buf);
      for (let i = 0, strLen = str.length; i < strLen; i++) {
        bufView[i] = str.charCodeAt(i);
      }
      return buf;
    }
    

    Submitted by admin 1242 days ago