Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Base64 encoding on the iPhone

How do I do Base64 encoding on the iPhone?

I have found a few examples that looked promising, but could never get any of them to work on the phone.

like image 899
respectTheCode Avatar asked May 19 '09 11:05

respectTheCode


People also ask

How do I find Base64 encoding?

In base64 encoding, the character set is [A-Z, a-z, 0-9, and + /] . If the rest length is less than 4, the string is padded with '=' characters. ^([A-Za-z0-9+/]{4})* means the string starts with 0 or more base64 groups.

How do I convert a file to Base64?

Convert Files to Base64 Just select your file or drag & drop it below, press the Convert to Base64 button, and you'll get a base64 string. Press a button – get base64. No ads, nonsense, or garbage. The input file can also be an mp3 or mp4.

How do I use Base64 decode?

To decode with base64 you need to use the --decode flag. With encoded string, you can pipe an echo command into base64 as you did to encode it. Using the example encoding shown above, let's decode it back into its original form. Provided your encoding was not corrupted the output should be your original string.


2 Answers

You can see an example here.

This is for iOS7+.

I copy the code here, just in case:

// Create NSData object NSData *nsdata = [@"iOS Developer Tips encoded in Base64"   dataUsingEncoding:NSUTF8StringEncoding];  // Get NSString from NSData object in Base64 NSString *base64Encoded = [nsdata base64EncodedStringWithOptions:0];  // Print the Base64 encoded string NSLog(@"Encoded: %@", base64Encoded);  // Let's go the other way...  // NSData from the Base64 encoded str NSData *nsdataFromBase64String = [[NSData alloc]   initWithBase64EncodedString:base64Encoded options:0];  // Decoded NSString from the NSData NSString *base64Decoded = [[NSString alloc]    initWithData:nsdataFromBase64String encoding:NSUTF8StringEncoding]; NSLog(@"Decoded: %@", base64Decoded); 
like image 133
Ferran Maylinch Avatar answered Oct 08 '22 10:10

Ferran Maylinch


Use this library to encode Base64.

It also supports ARC

like image 38
Dejell Avatar answered Oct 08 '22 09:10

Dejell