Reputation: 1336
I am implementing blowfish algorithm in my current app, I am getting the error in
#import "NSData+Base64Utilities.h"
which framework or file I have to add to remove this error?
I am using following code, Is I am following right approch?
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];
}
Upvotes: 0
Views: 604
Reputation: 150615
NSData+Base64Utilities.h
looks like the header file for a category that adds Base64 support to NSData.
The error is telling you that the compiler cannot find the files for the category. You need to add them to your project.
Edited to add
If you are targeting iOS7, then you can use the new NSData methods that handle base64 encodings. You don't need to use the category that you are trying to find.
Upvotes: 4