0

我正在传递一个在 iOS 上使用 RNCryptor 创建的 base 64 字符串,但无法解密它。将一些 console.logs 添加到 Node.JS 库的 Decrypt 函数时,它会在 !_hmac_is_valid 比较处停止。但是,我可以使用 .NET 库进行解密并且输出很好。

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];

    }

}

节点.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 测试

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
4

0 回答 0