title: No inverse error during encryption (node-rsa)
body: <p>I am trying to convert <a href="https://clover.app.box.com/s/rz18bni3bpmdrc8wc92xm4w8h9grrtty" rel="nofollow noreferrer">https://clover.app.box.com/s/rz18bni3bpmdrc8wc92xm4w8h9grrtty</a> from Java to node.js</p>
  <p>I am using the node-rsa package and getting <code>error:0306E06C:bignum routines:BN_mod_inverse:no inverse</code> when trying to encrypt using an imported public key.</p>
  <p>According to the clover example, I want to</p>
  <ul>
  <li>Parse the Base64 public key string (returned by the CDN). Obtain the modulus and exponent.</li>
  <li>Generate an RSA public key using the modulus and exponent values.</li>
  <li>Prepend the prefix value to the card number.</li>
  <li>Using the public key, encrypt the combined prefix and card number.</li>
  <li>Base64 encode the resulting encrypted data into a string.</li>
  </ul>
  <p>I was able to get the modulus and exponent, and it matches the result in Java:</p>
  <pre><code>modulus: 24130287975021244042702223805688721202041521798556826651085672609155097623636349771918006235309701436638877260677191655500886975872679820355397440672922966114867081224266610192869324297514124544273216940817802300465149818663693299511097403105193694390420041695022375597863889602539348837984499566822859405785094021038882988619692110445776031330831112388738257159574572412058904373392173474311363017975036752132291687352767767085957596076340458420658040735725435536120045045686926201660857778184633632435163609220055250478625974096455522280609375267155256216043291335838965519403970406995613301546002859220118001163241
  
  exponent: 415029
  </code></pre>
  <p>Now I want to create a public key with it, and encrypt a message:</p>
  <pre><code>    const key = new NodeRSA();
  
      // generate RSA public key using mod and exp values
      key.importKey({
          n: Buffer.from('24130287975021244042702223805688721202041521798556826651085672609155097623636349771918006235309701436638877260677191655500886975872679820355397440672922966114867081224266610192869324297514124544273216940817802300465149818663693299511097403105193694390420041695022375597863889602539348837984499566822859405785094021038882988619692110445776031330831112388738257159574572412058904373392173474311363017975036752132291687352767767085957596076340458420658040735725435536120045045686926201660857778184633632435163609220055250478625974096455522280609375267155256216043291335838965519403970406995613301546002859220118001163241', 'hex'),
          e: Buffer.from('415029', 'hex')
      }, 'components-public');
      
      // using public key, encrypt message
      // base64 encode encrypted data to string
      const encryptedString = key.encrypt(Buffer.from('message', 'hex'), 'base64', 'hex'); 
  </code></pre>
  <p>However, I am getting the no inverse error mentioned above. It seems to be caused by the modulus. If I change it to something shorter, the error goes away.</p>