-2

I am looking for obj-c code that is equivalent to this command

openssl enc -aes-128-cbc -k secret -P -md sha1

Once you type the above in command you get this output

salt=538C5F5ECAB7BFA2

key=43EB4C7D68263389D069381E48B6E0F3

iv =E26E4B49D75FA7C0CD82C40BB761B50A

Anand
  • 5
  • 2

1 Answers1

2

Any code I've seen using openssl from objective-c has used NSTask to run the openssl command.

Something like this should work (I've used something similar without any problems):

NSArray *args = [NSArray arrayWithObjects:@"enc", @"-aes-128-cbc", @"-k", @"secret", @"-P", @"-md", @"sha1", nil];

NSTask *task = [[NSTask alloc] init];

[task setLaunchPath:@"/usr/bin/openssl"];
[task setArguments:args];
[task launch];    // Run
[task waitUntilExit]; // Wait

Then your response should be in [task standardOutput].

MattR
  • 6,908
  • 2
  • 21
  • 30