1

我想使用 AirDrop 将我的应用程序加密的 NSObject“RND_PatientData”传输给另一个人。目前我的数据是使用以下代码保存的:

 - (RND_PatientData *)data {
if (_data != nil) return _data;

NSString *dataPath = [_docPath stringByAppendingPathComponent:kDataFile];
NSData *codedData = [[NSData alloc] initWithContentsOfFile:dataPath];
if (codedData == nil) return nil;
NSString *deviceName = [[UIDevice currentDevice] name];


NSData *decryptedData = [RNDecryptor decryptData:codedData withSettings:kRNCryptorAES256Settings password:deviceName error:nil];


NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:decryptedData];
_data = [unarchiver decodeObjectForKey:kDataKey];
[unarchiver finishDecoding];
return _data;
}

 - (void)saveData {

if (_data == nil) return;

[self createDataPath];

NSString *dataPath = [_docPath stringByAppendingPathComponent:kDataFile];
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:_data forKey:kDataKey];
[archiver finishEncoding];
NSError *error;
NSString *deviceName = [[UIDevice currentDevice] name];

NSData *encryptedData = [RNEncryptor encryptData:data
                                    withSettings:kRNCryptorAES256Settings
                                        password:deviceName
                                           error:&error];

[encryptedData writeToFile:dataPath atomically:YES];

此数据在保存之前也使用设备 UDID 和 RNDecryptor 库进行加密。现在,我希望 perosn 能够通过 AirDrop 传输数据。在发送方手机上解密数据,然后使用相同的框架在接收方手机上进行未加密传输和加密,还是使用发送方设备 UDID 对其进行加密传输和解密更好?

我将当前数据加载为 NSMutableArray :

   _patients = [RND_PatientDB loadDocs];

方法如下:

   + (NSMutableArray *)loadDocs {

// Get private docs dir
NSString *documentsDirectory = [RND_PatientDB getPrivateDocsDir];
NSLog(@"Loading patients from %@", documentsDirectory);

// Get contents of documents directory
NSError *error;
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];
if (files == nil) {
    NSLog(@"Error reading contents of documents directory: %@", [error localizedDescription]);
    return nil;
}
// Create Patients for each file
NSMutableArray *retval = [NSMutableArray arrayWithCapacity:files.count];
for (NSString *file in files) {
    if ([file.pathExtension compare:@"patients" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
        NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:file];
        RND_Patient *doc = [[RND_Patient alloc] initWithDocPath:fullPath];
        [retval addObject:doc];
    }
}

return retval;

  }
  + (NSString *)nextPatientDocPath {

// Get private docs dir
NSString *documentsDirectory = [RND_PatientDB getPrivateDocsDir];

// Get contents of documents directory
NSError *error;
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];
if (files == nil) {
    NSLog(@"Error reading contents of documents directory: %@", [error localizedDescription]);
    return nil;
}
// Search for an available name
int maxNumber = 0;
for (NSString *file in files) {
    if ([file.pathExtension compare:@"patients" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
        NSString *fileName = [file stringByDeletingPathExtension];
        maxNumber = MAX(maxNumber, fileName.intValue);
    }
}
// Get available name
NSString *availableName = [NSString stringWithFormat:@"%d.patients", maxNumber+1];
return [documentsDirectory stringByAppendingPathComponent:availableName];

}

我已尝试按照此处的说明通过 AirDrop 发送 NSArray,但我无法理解证书的工作原理。任何人都有资源我可以用来了解有关此过程的更多信息?我是否以正确的方式进行操作,或者是否有更简单的方法可以使用我的应用程序将包含 RND_PATIENT NSObject 的 NSMutableArray 发送给另一个人?

4

0 回答 0