Re: Base-64 decode (was Property List Editor)
Re: Base-64 decode (was Property List Editor)
- Subject: Re: Base-64 decode (was Property List Editor)
- From: Graham Jones <email@hidden>
- Date: Thu, 09 Jun 2005 13:26:24 -0400
Hi Steven,
Thanks a million! That's exactly what I was looking for. Too bad there's
not a more standard method, but it looks like this will do perfectly (can't
test until I'm off work tonight).
Just to confirm: in the xml file I'm reading from, the line looks like
this:
" <data>
AAAAAGADAzIAAAAAAAAAAAAAAAA=
</data>"
What part to I need to pass to the routine? Do I include the <data> tags
and the equals sign or just the letters that make the encoded number?
And I know part of the decoding process usually involves specifying the
number of outgoing digits... Is there anything I need to modify to make
sure it gets as close as possible to this:
"00000000 60030332 00000000 00000000 00000000"
Obviously I can easily add the spaces on my end.
Many thanks,
Graham Jones.
On 6/9/05 12:43 PM, "Steven K" wrote:
> I used this as a quick hack. It uses the property list base 64 decoder.
> I sneakily insert the base 64 string into an XML serialization of an
> empty property list and then decode the property list. My data is
> always very small, so this works for me.
>
> NSData* DecodeBase64 (NSString* inBase64)
> {
> NSMutableData* data = [[[NSMutableData alloc] init] autorelease];
> data = [[[NSPropertyListSerialization dataFromPropertyList: data
> format: NSPropertyListXMLFormat_v1_0 errorDescription: nil]
> mutableCopy] autorelease];
> char nul = 0;
> [data appendBytes: &nul length: 1];
> NSMutableString* plist = [NSMutableString stringWithUTF8String:
> reinterpret_cast < const char* > ([data bytes])];
> [plist replaceOccurrencesOfString: @"<data>" withString: [@"<data>"
> stringByAppendingString: inBase64] options: 0 range: NSMakeRange (0,
> [plist length])];
> data = [[[NSPropertyListSerialization propertyListFromData: [NSData
> dataWithBytes: [plist UTF8String] length: [plist length]]
> mutabilityOption:NSPropertyListImmutable format: nil errorDescription:
> nil] mutableCopy] autorelease];
> return data;
> }
>
> Regards,
>
> Steven Kramer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden