0

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];
} 
Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
QueueOverFlow
  • 1,336
  • 5
  • 27
  • 48

1 Answers1

4

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.

Abizern
  • 146,289
  • 39
  • 203
  • 257
  • yes, can you give me these file links, so I download it and add these files. – QueueOverFlow Sep 20 '13 at 14:31
  • 2
    @QueueOverFlow That's brilliant :D – trojanfoe Sep 20 '13 at 14:33
  • 2
    @QueueOverFlow It's not a standard extension and there are a couple of them. Since they don't have identical implementations you are better off using the same one that is used in this code that you seem to have found from somewhere. – Abizern Sep 20 '13 at 14:34
  • @trojanfoe I already do googling for "NSData+Base64Utilities.h", but i not get any answer regarding this error, I know the framework or file is missing, but not get exact what framework or file. – QueueOverFlow Sep 20 '13 at 14:35
  • 3
    @QueueOverFlow And what makes you think Abizern knows where to get those files? Just because he recognizes the issue does not mean he knows about that specific implementation. Please think for yourself. – trojanfoe Sep 20 '13 at 14:37
  • @QueueOverFlow It looks like any of them will do, you might have to tweak the actual method name that you call, but you are only turning data into Base64. Try Matt Gallagher's implementation, which I have as a gist at https://gist.github.com/Abizern/5629965 – Abizern Sep 20 '13 at 14:40
  • @trojanfoe I think my question should be ... What framework or file is required to use import "NSData+Base64Utilities.h" in objective C? – QueueOverFlow Sep 20 '13 at 14:40
  • @Abizern I am using this link : http://stackoverflow.com/questions/13507384/how-to-implement-blowfish-algorithm-in-ios – QueueOverFlow Sep 20 '13 at 14:44
  • 1
    @QueueOverFlow: You should ask the author of that answer what Base64 category they recommend. – Peter Hosey Sep 22 '13 at 02:01
  • @PeterHosey please have a look on my similar question : http://stackoverflow.com/questions/19031842/dycrypt-value-from-blowfish-objective-c – QueueOverFlow Sep 27 '13 at 11:20
  • @Abizern Please have a look on my similar question : http://stackoverflow.com/questions/19031842/dycrypt-value-from-blowfish-objective-c – QueueOverFlow Sep 27 '13 at 11:20