BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

Obfuscating JSON data

Forums > Swift

Hi All,

I'm saving my JSON data (via .fileExporter to iDrive) and, hurrah, it finally works saving all my classes and sub-classes. However, as the files are are on the iDrive they are easily accessible and their contents easily viewable, which exposes the underlying data - I don't really want that. The data is not going to be shared with any other app.

I appreciate that whatever I do is unlikely to deter any but the most casual user but is there a way I can simply obfuscate the data and still save as a text file?

Thanks in advance,

Jes

3      

There are a couple of things you could do:

Not Really Secure

Base64 encode the values before writing them to the file, when reading the file back in base64 decode them, this is not secure at all and anyone with technical knowledge is likely going to understand how to base64 decode.

Secure

Other 2 options would be to enxrypt the values prior to writing the file (and possibly best base64 encoding the encrypted value). This would leave the structure of the json file (or whatever file you are writing to disc) to remain as a file in that format, just the values would be unreadable

A better option, encrypt the whole file while writing it to disk. This would mean that a user opoening the fle wouldnt even know that it is a json file at all.

https://developer.apple.com/documentation/applearchive/encrypting_and_decrypting_a_string

Either of these secure options would require storing an encrpytion key. You could probably look at storing this in the keychain. Of course if this is lost it does mean that you would lose the data in the file.

3      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.