HISE Logo Forum
    • Categories
    • Register
    • Login

    Generate RSA activation code for machine code on the web page?

    Scheduled Pinned Locked Moved Scripting
    5 Posts 3 Posters 144 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • CatABCC
      CatABC
      last edited by

      I want to let users provide the machine code on the web page. The server backend uses the private key generated by HISE to generate an activation code for the machine code. After the user gets the activation code, he fills it in the plug-in to activate it.
      But I don't know the RSA key signing logic of HISE. Can anyone help me?
      This is the implementation steps I thought of:
      ▶1.Generate RSA key file in HISE and obtain PublicKey and PrivateKey
      ▶2.Put the PublicKey in the plugin
      ▶3.Put the PrivateKey on the server backend,
      ▶4.After the user logs in, fill in the machine code input box in the account
      ▶5.Click Submit Activation, the server uses PrivateKey to sign the machine code and generate an activation code
      ▶6.Fill in the activation code obtained into the activation code input box of the plug-in
      ▶7.The plugin uses the "FileSystem.decryptWithRSA(code, pubKey);" provided by HISE to verify the activation code

      //I am a new student at HISE._
      //Windows11 & MacOS Ventura 13.6.7_

      LindonL 1 Reply Last reply Reply Quote 0
      • LindonL
        Lindon @CatABC
        last edited by

        @CatABC this looks about right....

        HISE Development for hire.
        www.channelrobot.com

        1 Reply Last reply Reply Quote 0
        • CatABCC
          CatABC
          last edited by CatABC

          I found this in the source file of HISE. I think if I use JS to write a program with the same logic, I will give it a try.
          RSA.cpp

          //I am a new student at HISE._
          //Windows11 & MacOS Ventura 13.6.7_

          Christoph HartC 1 Reply Last reply Reply Quote 0
          • Christoph HartC
            Christoph Hart @CatABC
            last edited by

            @CatABC if you search the JUCE forum you‘ll find a PHP snippet that I hacked together in a previous life that does exactly that.

            CatABCC 1 Reply Last reply Reply Quote 0
            • CatABCC
              CatABC @Christoph Hart
              last edited by CatABC

              @Christoph-Hart I think I succeeded, thanks

               const d = BigInt('0x' + dHex);
                            const n = BigInt('0x' + nHex);
                      
                            const modulusBits = n.toString(2).length;
                            const modulusBytes = Math.ceil(modulusBits / 8);
                            const requiredHexLength = modulusBytes * 2; 
                            
                            const messageBuffer = Buffer.from(machineCode);
                            
                            const reversedBuffer = Buffer.from(messageBuffer).reverse();
                           
                            let value = BigInt('0x' + reversedBuffer.toString('hex'));
                
                            let result = 0n;
                            const modulus = n;
                            
                            while (value > 0n) {
                                
                                const remainder = value % modulus;
                                value = value / modulus; 
                           
                                const encryptedChunk = modExp(remainder, d, modulus);
                 
                                result = result * modulus + encryptedChunk;
                            }
              
                            let hexStr = result.toString(16).padStart(requiredHexLength, '0');
                            const finalBuffer = Buffer.from(hexStr, 'hex');
                            
                            return { activationCode: finalBuffer.toString('hex') };
              
              function modExp(base, exp, mod) {
                  let result = 1n;
                  base = base % mod;
                  while (exp > 0n) {
                      if (exp & 1n) 
                          result = (result * base) % mod;
                      exp = exp >> 1n;
                      base = (base * base) % mod;
                  }
                  return result;
              }
              

              //I am a new student at HISE._
              //Windows11 & MacOS Ventura 13.6.7_

              1 Reply Last reply Reply Quote 0
              • First post
                Last post

              23

              Online

              1.7k

              Users

              11.9k

              Topics

              103.3k

              Posts