title: Node-Forge: how can I convert the public key's modulo and exponent from decimal to hex?
body: <p>I'm using node forge (<a href="https://www.npmjs.com/package/node-forge" rel="nofollow noreferrer">https://www.npmjs.com/package/node-forge</a>) to create a public and private key pair (nodeforge.pki.rsa.generateKeyPair()) for testing purposes. The modulo (n) and exponent (e) of the public key is represented as an array of decimal values. However, the service that will provide the public key for encryption in production represents modulo and exponent in hex values. My question now is, how can I easily transform these values created by node forge from decimal to hex (I then want to use these values in NodeRSA (<a href="https://github.com/rzcoder/node-rsa" rel="nofollow noreferrer">https://github.com/rzcoder/node-rsa</a>)):</p>
  
  <pre><code>let pair = nodeforge.pki.rsa.generateKeyPair();
  
  var key = new NodeRSA();
  key.importKey({
      n: new Buffer(pair.publicKey.n.data, 'hex'),
      e: new Buffer(pair.publicKey.e.data, 'hex')
  });
  </code></pre>
  
  <p>The format of the public key provided by node forge is:</p>
  
  <pre><code>"publicKey": {
      "n": {
          "data": [
              95452259,
              62292680,
              234781115,
              46168802,
              112578909,
              58538647,
              44874864,
              186853653,
              197342112,
              104676488,
              229032986,
              262511790,
              101189381,
              134141598,
              55892282,
              145717908,
              78729040,
              107967002,
              62922480,
              120440374,
              262852613,
              65361518,
              128040269,
              29796715,
              171859902,
              201093939,
              131227011,
              165441987,
              9273795,
              130804401,
              240125365,
              221986724,
              32034899,
              180589760,
              106981089,
              188935555,
              21820073,
              96309166,
              54553752,
              100808208,
              198611546,
              11382488,
              139519439,
              212193674,
              26780810,
              225883560,
              101310123,
              78467199,
              181998612,
              8435669,
              195696345,
              41284550,
              129888967,
              137003722,
              74415901,
              92893643,
              57787310,
              143216416,
              42433969,
              100838107,
              34667532,
              136300465,
              185624737,
              67347,
              93800454,
              226047286,
              76852009,
              57120535,
              266741908,
              27775411,
              39685199,
              4113773,
              214629603,
              12
          ],
          "t": 74,
          "s": 0
      },
      "e": {
          "data": [
              65537
          ],
          "t": 1,
          "s": 0
      }
  </code></pre>
  
  <p>The reason I want to do that is that I want to test if the encryption facility works correctly (first, encrypt a value with the public key, then decrypt the value with the private key again), because the public key is provided by an external party and else I have no possibility to check, as the private key is not provided. </p>
  
  <p>Thanks a lot in advance!</p>