4

I'm having trouble encrypting data with node and decrypting with RNCryptor. My understanding is that RNCryptor uses a special data format?

The cryptotext is being generated as follows:

var crypto = require('crypto');
var cipher = crypto.createCipher('aes-256-cbc','InmbuvP6Z8');
var text = "123|123123123123123";
var crypted = cipher.update(text,'utf8','base64');
crypted += cipher.final('base64');

And I'm decrypting like this:

[RNDecryptor decryptData:plainText withPassword:password error:&error];

How am I supposed to do this? When I try to decrypt currently I get an empty NSData and no error.

Jack Rogers
  • 305
  • 3
  • 14

2 Answers2

0

Yes, RNCryptor outputs encrypted data in its own format. If you build this format in your own encryption code (and use the same encryption params), you can pass it to JNCryptor to decrypt.

For RNCryptor format version 3, the first 34 bytes are as follows:

  • byte[0] is the version (3).
  • byte[1] defines whether a password or a key is used (1 for password, 0 for key).
  • bytes[2-9] carry the encryption salt.
  • bytes[10-17] carry the HMAC salt.
  • bytes[18-33] carry the IV.

Then comes the encrypted ciphertext.

Then the last 32 bytes hold the (SHA256) HMAC for the ciphertext.

The spec is here: https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor-Spec-v3.md

J.B
  • 123
  • 1
  • 7
0

RNCryptor is more than just encryption, it is an entire secure "stack" including authentication, password key derivation, versioning and random iv. Since your encryption is just the encryption portion it will be incompatible.

Either use RNCryptor for the encryption or change to a simple decryption method. Since the question has a commoncrypto tag and the encryption code look like it might be Swift (there is no language tag) just consider using Common Crypto in Objective-C for the decryption. See the SO answer for example code.

Community
  • 1
  • 1
zaph
  • 111,848
  • 21
  • 189
  • 228