Question

I'm using node.js 0.10.12. I have generated 2048-bit RSA keypairs that I store as .pem files locally.

Using the built-in 'crypto' library that comes with node, I am trying to decrypt a block of data encrypted with the public RSA key mentioned above.

I've gotten this far:

var privateKey = fs.readFileSync('private.pem', { encoding: 'utf8' });

var cryptOpt = { key: /* PEM encoded private key */ privKey };

var cred = crypto.createCredentials( cryptOpt );

var rsa = crypto.createDecipheriv( 'rsa', cred.?key-in-binary-format?, cred.?initialization vector? );

I'm not sure I'm on the right path here.

• I don't know where the key is stored in binary form inside 'cred'.

• I don't know what to put in initialization-vector parameter.

The data will be encrypted using standard libraries on iOS, which, to my knowledge, does not allow the user to specify an initialization vector when encrypting with RSA.

I haven't been able to extract much knowledge or understanding from the node.js crypto docs: http://nodejs.org/api/crypto.html

Was it helpful?

Solution

As there isn't any asymmetric encryption happening in the nodejs, I think you are more or less lost in the woods. You will require another library if you want to encrypt anything with RSA. The openssl list-cipher-algorithms documentation that crypto.createCipher(algorithm, password) and crypto.createCipheriv(algorithm, key, iv) only lists symmetric algorithms such as AES and DES (etc.). An IV is only used for symmetric algorithms in general in either way. nodejs only seems to support RSA signing and verification.

I would really suggest to get deeper into the subject matter before continuing on your development path.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top