On Dec 5, 2010, at 2:31 PM, Adam Gerson <agers...@gmail.com> wrote: > Thanks to all who responded. Let me explain my situation a little > better. I am storing several string values into an XML file. I want to > obscure one of them. When I encrpyt the NSString to an NSdata I can > store the data as a string in XML, however when I read the string back > in I dont know how to convert it back to NSData to decrypt.
You'd better not be treating your XML data as an NSString. ;-) As long as you store your data in a CDATA section, the XML API you're using should give you the ability to get the raw data for a node. Alternatively, one of the convenient properties of Base64 is that it maps your data into a range of printable ASCII characters. So you can treat the Base64 data as ASCII and write it as a string in your XML document (being mindful, of course, of the document's encoding, which is most likely UTF-8 and therefore identical to ASCII for the Base64 output range). Then read it back in as a string, convert it to ASCII, and feed the raw ASCII data into the Base64 decoding algorithm. So to maximize flexibility without involving CDATAs, here's the process I'd use: Saving: Plaintext NSString --> Plaintext NSData (UTF-8; use -dataWithEncoding:) --> Base64 NSData (ASCII) --> Base64 NSString (use +stringWithData:encoding: to create this) --> your XML document Loading: Your XML document --> Base64 NSString (UTF-16) --> Base64 NSData (ASCII characters; use -dataWithEncoding to get this) --> Plaintext NSData (UTF-16) --> NSString (again use +stringWithData:encoding:) HTH, --Kyle Sluder _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com