how to convert array of bytes to base64 String in iphone?

前端 未结 6 2008
忘掉有多难
忘掉有多难 2021-02-15 09:20

I have a piece of code in vb. I need to convert array of bytes to base 64 string. Following is the vb code.

If arrLicence.Count > 0 Then

LicenceByt

6条回答
  •  难免孤独
    2021-02-15 09:47

    //strBusiCode = @"64-37-81-d4-39-6d";
    NSArray *tmp_arr = [strBusiCode componentsSeparatedByString:@"-"];
    NSMutableData *commandToSend= [[NSMutableData alloc] init];
    unsigned char whole_byte;
    char byte_chars[3] = {'\0','\0','\0'};
    int i;
    for (i=0; i < [tmp_arr count]; i++) {
        byte_chars[0] = [[tmp_arr objectAtIndex:i] characterAtIndex:0];
        byte_chars[1] = [[tmp_arr objectAtIndex:i] characterAtIndex:1];
        whole_byte = strtol(byte_chars, NULL, 16);
        [commandToSend appendBytes:&whole_byte length:1]; 
    }
    return commandToSend;
    

    This commandToSend is then converted to base64 data.

提交回复
热议问题