0

我正在我当前的应用程序中实现河豚算法,我得到了错误

#import "NSData+Base64Utilities.h"

我必须添加哪个框架或文件才能消除此错误?

我正在使用以下代码,我是否遵循正确的方法?

define PADDING_PHRASE @"       "

import "CryptoUtilities.h"
import "blowfish.h"
import "NSData+Base64Utilities.h"

@implementation CryptoUtilities

+ (NSString *)blowfishEncrypt:(NSData *)messageData usingKey:(NSData *)secretKey
{
NSMutableData *dataToEncrypt = [messageData mutableCopy];
NSMutableData *emptyData = [[PADDING_PHRASE dataUsingEncoding:NSUTF8StringEncoding] mutableCopy];

emptyData.length = 8 - [dataToEncrypt length] % 8;

// Here we have data ready to encipher
[dataToEncrypt appendData:emptyData];

BLOWFISH_CTX ctx;
Blowfish_Init (&ctx, (unsigned char*)[secretKey bytes], [secretKey length]);

NSRange aLeftRange, aRightRange;
NSData *aLeftBox, *aRightBox;
unsigned long dl = 0, dr = 0;

for (int i = 0; i < [dataToEncrypt length]; i += 8) { // Divide data into octets...
    // …and then into quartets
    aLeftRange = NSMakeRange(i, 4);
    aRightRange = NSMakeRange(i + 4, 4);

    aLeftBox = [dataToEncrypt subdataWithRange:aLeftRange];
    aRightBox = [dataToEncrypt subdataWithRange:aRightRange];

    // Convert bytes into unsigned long
    [aLeftBox getBytes:&dl length:sizeof(unsigned long)];
    [aRightBox getBytes:&dr length:sizeof(unsigned long)];

    // Encipher
    Blowfish_Encrypt(&ctx, &dl, &dr);

    // Put bytes back
    [dataToEncrypt replaceBytesInRange:aLeftRange withBytes:&dl];
    [dataToEncrypt replaceBytesInRange:aRightRange withBytes:&dr];
}

return [dataToEncrypt getBase64String];
} 
4

1 回答 1

4

NSData+Base64Utilities.h看起来像是为 NSData 添加 Base64 支持的类别的头文件。

该错误告诉您编译器找不到该类别的文件。您需要将它们添加到您的项目中。

编辑添加

如果您的目标是 iOS7,那么您可以使用处理 base64 编码的新 NSData 方法。您不需要使用您要查找的类别。

于 2013-09-20T14:30:10.200 回答