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

  • SEARCH
  • Home
  • 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 6608837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:39:07+00:00 2026-05-25T19:39:07+00:00

I have a NSString representing sha1 hash of some data and I need to

  • 0

I have a NSString representing sha1 hash of some data and I need to convert it to binary string, but cant find any good solution to do that. It should be equivalent to PHP’s pack function.

The result should be like this: 0xb7, 0xc7, 0x91, …, 0x90.

I than need to convert this binary to base64-encoded string.

  • 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-05-25T19:39:08+00:00Added an answer on May 25, 2026 at 7:39 pm

    You can easily to do so with a NSString+Base64 catalog.
    And the code should like this:

    #import "NSString+base64.h"
    
    //....
    //some codes
    //....
    NSString *yourNSString = @"Some string you want to be encoded";
    NSString *base64string = [yourNSString base64String];
    

    Here is the Code of NSString+Base64.h file for example:

    //
    //  NSString+Base64.h
    //  HudsonGrowl
    //
    //  Created by Benjamin Broll on 06.12.10.
    //
    //  This source code is licensed under the terms of the BSD license.
    //
    //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
    //  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    //  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 
    //  ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
    //  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    //  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    
    #import <Foundation/Foundation.h>
    
    
    @interface NSString (Base64)
    
    + (NSString *) base64StringFromData: (NSData *)data;
    
    - (NSString *)base64String;
    
    @end
    

    And the NSString+Base64.m file:

    //
    //  NSString+Base64.m
    //  HudsonGrowl
    //
    //  Created by Benjamin Broll on 06.12.10.
    //
    //  This source code is licensed under the terms of the BSD license.
    //
    //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
    //  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    //  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 
    //  ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
    //  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    //  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    
    #import "NSString+Base64.h"
    
    
    @implementation NSString (Base64)
    
    + (NSString *)encode:(const uint8_t *)input length:(NSInteger)length {
        // this code seems to be floating on a lot of stackoverflow posts.
        // i'm not aware of any license issues but let me know in case there are
        // problems including the source in this project.
    
        static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    
        NSMutableData *data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
        uint8_t *output = (uint8_t *)data.mutableBytes;
    
        for (NSInteger i = 0; i < length; i += 3) {
            NSInteger value = 0;
            for (NSInteger j = i; j < (i + 3); j++) {
                value <<= 8;
    
                if (j < length) {
                    value |= (0xFF & input[j]);
                }
            }
    
            NSInteger index = (i / 3) * 4;
            output[index + 0] =                    table[(value >> 18) & 0x3F];
            output[index + 1] =                    table[(value >> 12) & 0x3F];
            output[index + 2] = (i + 1) < length ? table[(value >> 6)  & 0x3F] : '=';
            output[index + 3] = (i + 2) < length ? table[(value >> 0)  & 0x3F] : '=';
        }
    
        return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];
    }
    
    + (NSString *) base64StringFromData: (NSData *)data {
        return [self encode:data.bytes length:data.length];
    }
    
    - (NSString *)base64String {
        NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding];
        return [NSString base64StringFromData:data];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following string representing a date & time NSString *shortDateString = @Sat28Apr2012
I have a NSString [WORD] that has some length [LEN]. What i need to
I have NSString @ (\n Bi_ss \n) I want to get String @Bi_ss Any
I have: NSString *promise = @thereAreOtherWorldsThanThese; which I'm trying to transform into the string:
I have an NSString which is splitted into set of characters. I need to
I have an NSString *string=@606 and I want to add a : colon after
I have a set of NSString representing the names of the files in a
I have a TTLauncherView with some TTLauncherItems . These show badges, representing messages from
I have a class called Shop that contains data members ( NSString , NSInteger
I have an NSString in Objective-C that I want to find the size of

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.