• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: base64Binary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: base64Binary


  • Subject: Re: base64Binary
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Wed, 14 Apr 2010 22:47:52 +0200

Google provide some class to do that too.

See GTMBase64 classes at http://code.google.com/p/google-toolbox-for-mac/source/browse/#svn/trunk/Foundation

Le 14 avr. 2010 à 22:00, joby abraham a écrit :

> Hi Bialecki,
>
> for base64 encoding/decoding you can use openSSL Library which providing by
> MAC OS.
>
> I can give you code snippets for encoding and decoding string.
>
> #include <openssl/bio.h>
> #include <openssl/evp.h>
>
> - (NSString *)base64EncodedString
> {
>    // Construct an OpenSSL context
>    BIO *context = BIO_new(BIO_s_mem());
>
>    // Tell the context to encode base64
>    BIO *command = BIO_new(BIO_f_base64());
>    context = BIO_push(command, context);
>
>    // Encode all the data
>    BIO_write(context, [self bytes], [self length]);
>    BIO_flush(context);
>
>    // Get the data out of the context
>    char *outputBuffer;
>    long outputLength = BIO_get_mem_data(context, &outputBuffer);
>    NSString *encodedString = [NSString
>        stringWithCString:outputBuffer
>        length:outputLength];
>
>    BIO_free_all(context);
>
>    return encodedString;
> }
>
>
> + (NSData *)dataByDase64DecodingString:(NSString *)decode
> {
>    decode = [decode stringByAppendingString:@"\n"];
>    NSData *data = [decode dataUsingEncoding:NSASCIIStringEncoding];
>
>    // Construct an OpenSSL context
>    BIO *command = BIO_new(BIO_f_base64());
>    BIO *context = BIO_new_mem_buf((void *)[data bytes], [data length]);
>
>    // Tell the context to encode base64
>    context = BIO_push(command, context);
>
>    // Encode all the data
>    NSMutableData *outputData = [NSMutableData data];
>
>    #define BUFFSIZE 256
>    int len;
>    char inbuf[BUFFSIZE];
>    while ((len = BIO_read(context, inbuf, BUFFSIZE)) > 0)
>    {
>        [outputData appendBytes:inbuf length:len];
>    }
>
>    BIO_free_all(context);
>    [data self]; // extend GC lifetime of data to here
>
>    return outputData;
> }
>
>
> 2010/4/14 Bartosz Bialecki <email@hidden>
>
>> Hi everyone,
>> I have some problem. I'm writing a web service client and one of my xml
>> request require a data encoded as base64Binary. I'm using NSData type in my
>> application but data are encoded as base64. Do you know any solution?
>>
>> Best regards,
>> Bartosz Bialecki
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>>
>> This email sent to email@hidden
>>
>
>
>
> --
> Thanks & Regards,
> Joby Abraham.
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

-- Jean-Daniel




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: base64Binary
      • From: joby abraham <email@hidden>
References: 
 >base64Binary (From: Bartosz Bialecki <email@hidden>)
 >Re: base64Binary (From: joby abraham <email@hidden>)

  • Prev by Date: Re: Efficiently iterating files on the iPhone
  • Next by Date: Re: base64Binary
  • Previous by thread: Re: base64Binary
  • Next by thread: Re: base64Binary
  • Index(es):
    • Date
    • Thread