1

Using Xcode 4, I'm attempting to build the SSCrypto framework for use with an iOS app.

In Build Settings, when I change the base SDK to Latest iOS, I get this error:

target specifies product type 'com.apple.product-type.framework', but there's no such product type for the 'iphoneos' platform

My googling and searching has turned up empty, so I feel I'm missing something obvious...

How do I get SSCrypto framework to work on iOS?

David Nix
  • 3,324
  • 3
  • 32
  • 51
  • What crypto functions do you specifically need? – zaph Sep 08 '11 at 00:51
  • De-code base64 strings, then de-crypt the strings. The strings were encrypted using OpenSSL (AES-256). – David Nix Sep 08 '11 at 15:12
  • CommonCrypto (included in iOS) will handle AES-256 easily. For Base64 see: http://stackoverflow.com/questions/392464/any-base64-library-on-iphone-sdk/800976#800976 – zaph Sep 08 '11 at 15:23

2 Answers2

2

For iOS only static libraries can be used, not frameworks with dynamic libraries.

Instead use CommonCrypto, it is plain C but not really hard to use. Do insure that you use all the same setting, mode, IV (if necessary for the mode), padding and key.

Add the Security.framework to the project

#import <CommonCrypto/CommonCryptor.h>

+ (NSData *)doCipher:(NSData *)dataIn
                  iv:(NSData *)iv
                 key:(NSData *)symmetricKey
             context:(CCOperation)encryptOrDecrypt
{
    CCCryptorStatus ccStatus   = kCCSuccess;
    size_t          cryptBytes = 0;    // Number of bytes moved to buffer.
    NSMutableData  *dataOut    = [NSMutableData dataWithLength:dataIn.length + kCCBlockSizeAES256];

    ccStatus = CCCrypt( encryptOrDecrypt,
                       kCCAlgorithmAES256,
                       kCCOptionPKCS7Padding,
                       symmetricKey.bytes, 
                       kCCKeySizeAES256,
                       iv.bytes,
                       dataIn.bytes,
                       dataIn.length,
                       dataOut.mutableBytes,
                       dataOut.length,
                       &cryptBytes);

    if (ccStatus != kCCSuccess) {
        // Handle error
        NSLog(@"CCCrypt status: %d", ccStatus);
    }

    dataOut.length = cryptBytes;

    return dataOut;
}

For Base64 see: SO answer

Community
  • 1
  • 1
zaph
  • 111,848
  • 21
  • 189
  • 228
  • Not technically true; you could (and probably still can) build and use dynamic libs if you jump through enough hoops. There's just not much point, since the lib won't be shared with other apps so it might as well be static, unless it's LGPL or so. – tc. Sep 08 '11 at 02:06
  • @CocoaFu Wow, this is fantastic. However, Xcode is not recognizing CCOperation. What do I need to import in the header? – David Nix Sep 08 '11 at 16:45
0

Xcode 4 removed a lot of target types, presumably because Apple thought it was confusing people.

Build a static library instead, or just include the files in your project.

tc.
  • 33,468
  • 5
  • 78
  • 96
  • Attempting to just include the files: Building for iOS does not allow you to link libssl.dylib or libcrypto.dylib, which SSCrypto needs. Hmmm... – David Nix Sep 08 '11 at 17:00
  • 1
    There's the problem, then: iOS does not include OpenSSL (as far as I know). You can build that too, but then it gets messy... – tc. Sep 09 '11 at 14:11