NSData (ACSecureFile) category

Use this category if you to encrypt the data that your app stores. If you want to share the encrypted data with another AppConnect app, see NSData (ACSecureFile) category.

Each method in the NSData (ACSecureFile) category corresponds to a method in the NSData class, but provides a secure version of the functionality. For more information about the functionality and usage, see NSData in developer.apple.com.

Note the following:

The url parameter in the category methods must be a file URL, and point to a regular file.

The category methods that return an NSError object set the properties on the object as described in NSError objects that secure Objective-C methods return.

Ivanti recommends that you only use the category methods that return an NSError object. However, to be consistent with the NSData class, the category includes secure versions of NSData methods that do not return an NSError object.

The following table shows each added method and its corresponding method in NSData.

 

Table 24.   NSData (ACSecureFile) category methods

Method in category

Corresponding method in NSData

+ (id)dataWithContentsOfSecureFile:

(NSString *)path;

+ (id)dataWithContentsOfFile:

(NSString *)path;

+ (id)dataWithContentsOfSecureFile:

(NSString *)path

options:(NSDataReadingOptions)mask

error:(NSError **)errorPtr;

+ (id)dataWithContentsOfFile:

(NSString *)path

options:(NSDataReadingOptions)mask

error:(NSError **)errorPtr;

+ (id)dataWithContentsOfSecureURL:

(NSURL *)url;

+ (id)dataWithContentsOfURL:

(NSURL *)url;

+ (id)dataWithContentsOfSecureURL:

(NSURL *)url

options:(NSDataReadingOptions)mask

error:(NSError **)errorPtr;

+ (id)dataWithContentsOfURL:

(NSURL *)url

options:(NSDataReadingOptions)mask

error:(NSError **)errorPtr;

- (id)initWithContentsOfSecureFile:

(NSString *)path;

- (id)initWithContentsOfFile:

(NSString *)path;

- (id)initWithContentsOfSecureFile:

(NSString *)path

options:(NSDataReadingOptions)mask

error:(NSError **)errorPtr;

- (id)initWithContentsOfFile:

(NSString *)path

options:(NSDataReadingOptions)mask

error:(NSError **)errorPtr;

- (id)initWithContentsOfSecureURL:

(NSURL *)url;

- (id)initWithContentsOfURL:

(NSURL *)url;

- (id)initWithContentsOfSecureURL:

(NSURL *)url

options:(NSDataReadingOptions)mask

error:(NSError **)errorPtr;

- (id)initWithContentsOfURL:

(NSURL *)url

options:(NSDataReadingOptions)mask

error:(NSError **)errorPtr;

- (BOOL)writeToSecureFile:

(NSString *)path

atomically:(BOOL)flag;

- (BOOL)writeToFile:

(NSString *)path

atomically:(BOOL)flag;

- (BOOL)writeToSecureFile:

(NSString *)path

options:(NSDataWritingOptions)mask

error:(NSError **)errorPtr;

- (BOOL)writeToFile:

(NSString *)path

options:(NSDataWritingOptions)mask

error:(NSError **)errorPtr;

- (BOOL)writeToSecureURL:

(NSURL *)aURL

atomically:(BOOL)atomically;

- (BOOL)writeToURL:

(NSURL *)aURL

atomically:(BOOL)atomically;

 

- (BOOL)writeToSecureURL:

(NSURL *)aURL

options:(NSDataWritingOptions)mask

error:(NSError **)errorPtr;

- (BOOL)writeToURL:

(NSURL *)aURL

options:(NSDataWritingOptions)mask

error:(NSError **)errorPtr;

Example:

The following example shows how to use NSData category methods to:

1. Create a secure file and write data to it.
2. Read the contents of the secure file.

For brevity, the example does not include error handling.

- (void)NSDataCategoryExample
{
	NSError *error;
 
	// Read the contents of /etc/group.
	NSData *etcGroupData = [NSData dataWithContentsOfFile:@"/etc/group"];
 
	// Write the contents of /etc/group to a secure file.
	NSString *secureFileName = @"/tmp/group.sec";
	[etcGroupData writeToSecureFile:secureFileName options:0 error:&error];
 
	// Read the contents of the secure file.
	NSData *secureFileData = 				 
		[NSData dataWithContentsOfSecureFile:secureFileName options:0 error:&error];
 
	// Note: The contents of NSData objects 'secureFileData' and 'etcGroupData'
	// are identical.
}