iOS RNCryptor (encrypting) and Node.JS jscryptor (decrypting)

112 Views Asked by At

I'm passing a base 64 string created with RNCryptor on iOS and am unable to decrypt it. When adding some console.logs to the Node.JS library's Decrypt function, it stops at the !_hmac_is_valid comparison. I can, however, use the .NET library to decrypt and the output is fine.

iOS

- (void) sendCommand: (NSString *) command {
    NSData *data = [command dataUsingEncoding:NSUTF8StringEncoding];

    NSString *key = @"1234567890123456789012";
    NSData *encryptedData = [RNEncryptor encryptData:data
                                        withSettings:kRNCryptorAES256Settings
                                            password:key
                                               error:&error];

    if (currentPeripheral != nil && currentPeripheral.state == CBPeripheralStateConnected) {
        [currentPeripheral writeValue:encryptedData forCharacteristic:currentCharacteristic type:CBCharacteristicWriteWithResponse];

    }

}

Node.JS

function decryptString(data) {
    const RNCryptor = require('jscryptor');
    const password = '1234567890123456789012';

    try {
        console.log(RNCryptor.Decrypt(data.toString('base64'), password).toString('ascii')); // undefined when trying to decrypt the iOS string
    }
    catch (e) {}
}

VB.NET test

Public Function DecryptString(encryptedString) As String
    Dim password = "1234567890123456789012"
    Dim decryptor As New Decryptor
    Dim decryptedData As String = decryptor.Decrypt(encryptedString, password)

    Return decryptedData
End Function
0

There are 0 best solutions below