0

I need to convert Base64 string to Byte array (unsigned char*):

I tried this way, but it return half byte (Hex decimal) value in every array field.

My code:

    NSMutableString *Results = "base64 data";  
    NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:Results options:0];
    NSUInteger len = decodedData.length;
    NSMutableString* pointerResult = [NSMutableString stringWithCapacity:(2 * len)];
    const unsigned char* pointer = [decodedData bytes];
    for(NSUInteger i = 0; i < len; i++, pointer++) {
        [pointerResult appendFormat:@"%02x", (long)*pointer];
    }
    NSString *output = [NSString stringWithString:pointerResult];
    unsigned char *string = (unsigned char *) [output UTF8String];

What should I do to convert Base64 string to byte array (unsigned char*) (every byte).

Note:

1- I tried %0x but not return right data.

2- I need to move on my byte array later to separate it to some byte arrays.

Yasser Ajaj
  • 119
  • 1
  • 10

0 Answers0