Archived Forum Post

Index of archived forum posts

Question:

RSA importpublickey fails on NodeJS ans MacOS

Nov 11 '15 at 09:20

Hello there,

I'm trying to use RSA lib but its not working to import the public key:

let os = require('os');
if (os.platform() == 'linux') {
  if (os.arch() == 'x86') var chilkat = require('chilkat_linux32');
  else var chilkat = require('chilkat_linux64');
} else if (os.platform() == 'darwin') {
  var chilkat = require('chilkat_macosx');
}

var rsa = new chilkat.Rsa();
if (!rsa.UnlockComponent("Anything for 30-day trial")) throw new Error("RSA component unlock failed");
var rsa_key = "<RSAKeyValue><Modulus>vRndy7JYFnVae/3XCTPGMuwNlFMWrETDkHH2nFP/tnuFDa/n/sh3nZ57LBHu2zpSfLcJ93uXWZ+rCGCxc6lRU4qZU1+WubGXcPeM9ZZDN3uihKn/24YF7Y8KyWPr+QeBz8nNcJyPuPYPbx2YFGx/+AhsZ/KLzk4EoaO5nr/84Of5afWAORFSdt76Ac0tGp3qEvvScIRIy2PdF/9hE4iEYYC+sgy4eAIOjmQXWcuXz3d27fAMDtc3sxZtAb/klkN226sdCUFeTIIxqiOmq17gESYnWFifX55TcboqWmhHLfXCyl8vX/O56lHeNoinCaIQOBg6UrWj1NmOOf/7aevhElictDAJgRCBETuwORPdfJqzfgXS5e1rzMuKRF6qBIGtKLPwnCUgBioZAyqrjaLImQlEphGZJ3DsVPlKn43xo7t8I5HSF8O3TBNY2Zq2yrWaVLiWau5Jmr21k0oY0WS5FLt7HnzasbhcPIPjJ7awM4VtyNcmC8cIr9h9CMAjbXmmh/aX7xI2S0tf5MsUzeOJVXMpVDP7e/6bXh7UMt22omfDsKwqYCt3YtIbioi757TIJ5GQXyLK4Z85iWVneFKI/tvRGrxfkzU8FJRvgPGIUQRBLhy9FE76BACr7RqJZe5aL0e5jugoIwCfnDRQHrHuArcRWhBh1aKmX90KfVi+dOk=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";

rsa.ImportPublicKey(rsa_key);
rsa.Charset = "utf-8";
rsa.EncodingMode = "base64";
console.log(rsa.LastErrorText);

But the import public key fails without a reason:

ChilkatLog:
  ImportPublicKey:
    DllDate: Oct 29 2015
    ChilkatVersion: 9.5.0.54
    UnlockPrefix: Anything for 30-day trial
    Architecture: Little Endian; 64-bit
    Language: Mac OS X Node.js
    VerboseLogging: 0
    Failed.
  --ImportPublicKey
--ChilkatLog

Im running on OSX.

Even if i try the example code on: http://www.example-code.com/nodejs/rsa_charset.asp The same thing happens...


Answer

There's an error in the example, and I'll update it right away. (Sorry about that!)

The XML for an RSA public key should be "<RSAPublicKey> ... </RSAPublicKey>" instead of "<RSAKeyValue> ... </RSAKeyValue>"