• 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: Obscuring an NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obscuring an NSString


  • Subject: Re: Obscuring an NSString
  • From: Kyle Sluder <email@hidden>
  • Date: Sun, 5 Dec 2010 20:41:55 -0800

On Dec 5, 2010, at 2:31 PM, Adam Gerson <email@hidden> 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 (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: Obscuring an NSString
      • From: Adam Gerson <email@hidden>
References: 
 >Obscuring an NSString (From: Adam Gerson <email@hidden>)
 >Re: Obscuring an NSString (From: Richard Somers <email@hidden>)
 >Re: Obscuring an NSString (From: Adam Gerson <email@hidden>)

  • Prev by Date: Re: Cocoa/Objective-C flat name space problems
  • Next by Date: Re: Problem Binding to UserDefaults
  • Previous by thread: Re: Obscuring an NSString
  • Next by thread: Re: Obscuring an NSString
  • Index(es):
    • Date
    • Thread