Re: Obscuring an NSString

2010-12-05 Thread Adam Gerson
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.

Adam


On Thu, Dec 2, 2010 at 1:57 PM, Richard Somers
rsomers.li...@infowest.com wrote:
 Try the open source SSCrypto.framework. It is a Cocoa wrapper around OpenSSL
 encryption and decryption. It works well.

 http://septicus.com/products/opensource/

 --Richard Somers

 On Dec 2, 2010, at 6:30 AM, Adam Gerson wrote:

 I am writing an NSString to a file and I would like to obscure it in a two
 way reversible fashion.


___

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


Re: Obscuring an NSString

2010-12-05 Thread Ricky Sharp

On Dec 5, 2010, at 4:31 PM, Adam Gerson 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.


input string (NSString) -- UTF-8 representation (NSData) -- optional 
encryption such as XOR -- hex string (NSString)

this is fully reversible of course.

___
Ricky A. Sharp mailto:rsh...@instantinteractive.com
Instant Interactive(tm)   http://www.instantinteractive.com



___

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


Re: Obscuring an NSString

2010-12-05 Thread Kyle Sluder
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


Obscuring an NSString

2010-12-02 Thread Adam Gerson
I am writing an NSString to a file and I would like to obscure it in a
two way reversible fashion. It doesn't have to be major hacker proof,
just not understandable by an average person. I need to be able to
read the value back in from the file and convert it back to clear
text. In php I would just use base64 encode / decode. All the cocoa
examples I have found show converting in base64 between nsstring and
nsdata. Is there a smiple function I can pass an NSString through to
obscure it while keeping it as a string, then reverse it back to clear
text in a reliable way?

Thanks,
Adam
___

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


RE: Obscuring an NSString (Adam Gerson)

2010-12-02 Thread Kirk Kerekes
If you convert the NSString into an NSData,(dataUsingEncoding:) and then Base64 
encode it into an NSString, doesn't that get you what you want?


 I am writing an NSString to a file and I would like to obscure it in a
 two way reversible fashion. It doesn't have to be major hacker proof,
 just not understandable by an average person. I need to be able to
 read the value back in from the file and convert it back to clear
 text. In php I would just use base64 encode / decode. All the cocoa
 examples I have found show converting in base64 between nsstring and
 nsdata. Is there a smiple function I can pass an NSString through to
 obscure it while keeping it as a string, then reverse it back to clear
 text in a reliable way?
 
 Thanks,
 Adam
___

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


Re: Obscuring an NSString (Adam Gerson)

2010-12-02 Thread jonat...@mugginsoft.com

On 2 Dec 2010, at 17:32, Kirk Kerekes wrote:

 If you convert the NSString into an NSData,(dataUsingEncoding:) and then 
 Base64 encode it into an NSString, doesn't that get you what you want?
 


Converting the string to an NSData rep and dumping out as a property list will 
encode the NSData as base-64

+ (NSInteger)writePropertyList:(id)plist toStream:(NSOutputStream *)stream 
format:(NSPropertyListFormat)formatoptions:(NSPropertyListWriteOptions)opt 
error:(NSError **)error

Regards

Jonathan Mitchell

Developer
Mugginsoft LLP
http://www.mugginsoft.com___

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


Re: Obscuring an NSString

2010-12-02 Thread Richard Somers
Try the open source SSCrypto.framework. It is a Cocoa wrapper around  
OpenSSL encryption and decryption. It works well.


http://septicus.com/products/opensource/

--Richard Somers

On Dec 2, 2010, at 6:30 AM, Adam Gerson wrote:

I am writing an NSString to a file and I would like to obscure it in  
a two way reversible fashion.


___

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


Re: Obscuring an NSString

2010-12-02 Thread Kyle Sluder
On Thu, Dec 2, 2010 at 5:30 AM, Adam Gerson agers...@gmail.com wrote:
 I am writing an NSString to a file and I would like to obscure it in a
 two way reversible fashion. It doesn't have to be major hacker proof,
 just not understandable by an average person. I need to be able to
 read the value back in from the file and convert it back to clear
 text. In php I would just use base64 encode / decode. All the cocoa
 examples I have found show converting in base64 between nsstring and
 nsdata. Is there a smiple function I can pass an NSString through to
 obscure it while keeping it as a string, then reverse it back to clear
 text in a reliable way?

No. You need to go through NSData first.

--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


Re: Obscuring an NSString (Adam Gerson)

2010-12-02 Thread Kyle Sluder
On Thu, Dec 2, 2010 at 9:49 AM, jonat...@mugginsoft.com
jonat...@mugginsoft.com wrote:
 Converting the string to an NSData rep and dumping out as a property list 
 will encode the NSData as base-64

This is an implementation detail. You shouldn't rely on it.

--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


Re: Obscuring an NSString (Adam Gerson)

2010-12-02 Thread jonat...@mugginsoft.com

On 2 Dec 2010, at 20:37, Kyle Sluder wrote:

 On Thu, Dec 2, 2010 at 9:49 AM, jonat...@mugginsoft.com
 jonat...@mugginsoft.com wrote:
 Converting the string to an NSData rep and dumping out as a property list 
 will encode the NSData as base-64
 
 This is an implementation detail. You shouldn't rely on it.
 
 

The DTD for plist version 1.0 states:

!ELEMENT data (#PCDATA) !-- Contents interpreted as Base-64 encoded --

Therefore I think we can rely on this implementation detail for now.

Regards

Jonathan Mitchell

Developer
Mugginsoft LLP
http://www.mugginsoft.com

___

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


Re: Obscuring an NSString

2010-12-02 Thread Graham Cox

On 03/12/2010, at 12:30 AM, Adam Gerson wrote:

 I am writing an NSString to a file and I would like to obscure it in a
 two way reversible fashion. It doesn't have to be major hacker proof,
 just not understandable by an average person. I need to be able to
 read the value back in from the file and convert it back to clear
 text. In php I would just use base64 encode / decode. All the cocoa
 examples I have found show converting in base64 between nsstring and
 nsdata. Is there a smiple function I can pass an NSString through to
 obscure it while keeping it as a string, then reverse it back to clear
 text in a reliable way?


Lots of ways to do this, but a very simple one is to take advantage of the fact 
that A ^ B ^ B = A, in other words, if you XOR something twice you get back the 
original.

So convert to bytes [NSString dataUsingEncoding], then XOR each byte with some 
constant. Save the data. To recover plain text, XOR with the same constant and 
convert back to a string. The constant should not be 0.

Note that this only obfuscates slightly - the text looks pretty scrambled but 
is still open to simple techniques such as frequency analysis. If you change 
the constant in some predetermined fashion for each byte you can make a much 
stronger 'encryption'.

(typed in mail):


- (NSData*) reversiblyObfuscateData:(NSData*) dataIn
{
NSMutableData* dataOut = [NSMutableData data];

NSUInteger n;
char byte;

for( n = 0; n  [dataIn length]; ++n )
{
[dataIn getBytes:byte length:1];
byte ^= 0xA5;
[dataOut appendBytes:byte length:1];
}

return dataOut;
}

--Graham___

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


Re: Obscuring an NSString

2010-12-02 Thread Fritz Anderson
On 2 Dec 2010, at 7:30 AM, Adam Gerson wrote:

 I am writing an NSString to a file and I would like to obscure it in a
 two way reversible fashion. It doesn't have to be major hacker proof,
 just not understandable by an average person. I need to be able to
 read the value back in from the file and convert it back to clear
 text. In php I would just use base64 encode / decode. All the cocoa
 examples I have found show converting in base64 between nsstring and
 nsdata. Is there a smiple function I can pass an NSString through to
 obscure it while keeping it as a string, then reverse it back to clear
 text in a reliable way?

Base64 works only bytewise, whereas NSString is notionally UTF-16, so the 
base64 result really is byte data (representable as NSData), and not a string.

If the only purpose of the base64 data is to be the contents of a file, I don't 
see your objection to its being NSData at the last step before writing and the 
first step after reading. You already have methods to get an NSString whenever 
you want it. Why is that not enough? You seem to have a requirement you're not 
telling us about.


— F

___

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