TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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,



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.


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.

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.


Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

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.