Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8274269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:41:13+00:00 2026-06-08T07:41:13+00:00

My C++ knowledge stinks. I have a code provided by Apple where they, as

  • 0

My C++ knowledge stinks. I have a code provided by Apple where they, as usually, provided an incomplete solution.

On this code they provide two empty methods headers:

- (NSString *)encodeBase64:(const uint8_t *)input length:(NSInteger)length
- (NSString *)decodeBase64:(NSString *)input length:(NSInteger *)length

These methods, in theory, should call two C++ style functions, but as my C++ knowledge stinks infinity squared plus one, please fill the ???

- (NSString *)encodeBase64:(const uint8_t *)input length:(NSInteger)length
{
   // I need to call base64_encode and return its results as string... is this correct?

   return [NSString stringWithUTF8String:
       base64_encode(input, ???)];
    // ??? I need to pass a NSInteger to a size_t... how do I do that?
}


- (NSString *)decodeBase64:(NSString *)input length:(NSInteger *)length
{

// ??? = this method receives a NSInteger *length variable. How do I pass that
// to a size_t * variable required by base64_decode?

    NSString *st = [[NSString alloc] initWithBytes:
                    base64_decode([input UTF8String], ???)
                                            length:&length
                                          encoding: NSUTF8StringEncoding];

    return st;
}

these 2 methods call these C++ functions

char* base64_encode(const void* buf, size_t size)
{
   // bla bla bla
}

void* base64_decode(const char* s, size_t* data_len_ptr)
{
    // bla bla bla
}

thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:41:14+00:00Added an answer on June 8, 2026 at 7:41 am

    First, if you want to do base64 encode/decode you will find it easier to start with a properly worked out example for how to do so. Matt Gallagher gives easy recipes for doing this in Base64 encoding options on the Mac and iPhone.

    If you really want to flesh out your example, keep in mind that NSInteger is a long and size_t is an unsigned long. You could replace the lines in question with the following:

    - (NSString *)encodeBase64:(const uint8_t *)input length:(NSInteger)length
    {
        return [NSString stringWithUTF8String:base64_encode(input, (size_t)length)];
    }
    
    - (NSString *)decodeBase64:(NSString *)input length:(NSInteger *)length
    {
        size_t retLen;
        uint8_t *retStr = base64_decode([input UTF8String], &retLen);
        if (length)
            *length = (NSInteger)retLen;
        NSString *st = [[[NSString alloc] initWithBytes:retStr
                                            length:retLen
                                          encoding:NSUTF8StringEncoding] autorelease];
        free(retStr);    // If base64_decode returns dynamically allocated memory
        return st;
    }
    

    (Remove the autorelease if you are compiling under ARC.)

    Note that an arbitrary sequence of bytes is not guaranteed to be a valid UTF-8 string. This API allows you to send in arbitrary bytes but assumes it will decode to a valid UTF-8 string, which is not necessarily true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My knowledge of code just doesn't go this deep, and I have no idea
I have some knowledge of CGI scripts and how they work and came to
I have very limited knowledge of C#. My goal is to provide a C++
I have limited knowledge of jQuery...I need help with this specific instance of a
My knowledge of regex is very weak. So far I have manage to create
My knowledge of xml and php is somewhat basic but have been able to
My knowledge of Lambda expressions is a bit shaky, while I can write code
Just a knowledge question which I would like to ask: For example, I have
My knowledge of C++ at this point is more academic than anything else. In
I have searched the knowledge base high and low, but nothing seems to give

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.