开发者

Build failure when trying to build SSCrypto framework for use with iOS

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...

开发者_如何学Go

How do I get SSCrypto framework to work on iOS?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜