2

I am working on a Cocoa application (Objective-C) where it needs to determine if the FileVault is turned on. I tried searching the .plist for FileVault but no success.

Any help would be appreciated,

Thanks in advance :) cheers

l'L'l
  • 44,951
  • 10
  • 95
  • 146
BlackPearl12
  • 306
  • 5
  • 20
  • This is not an API but at least there is [fdesetup tool](https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man8/fdesetup.8.html) – SergGr Feb 27 '17 at 07:49

1 Answers1

3

It's fairly simple via NSTask:

@autoreleasepool {
    NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath:@"/usr/bin/fdesetup"];
    [task setArguments:[NSArray arrayWithObjects:@"status", nil]];

    NSPipe *pipe = [NSPipe pipe];
    [task setStandardOutput: pipe];

    NSFileHandle *file = [pipe fileHandleForReading];
    [task launch];

    NSData *data = [file readDataToEndOfFile];
    NSString *string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];

    NSLog (@"%@", string); // FileVault is Off/On.
}

There's likely a way to check via SecKeychain, although for a quick check that might be overkill.

l'L'l
  • 44,951
  • 10
  • 95
  • 146