UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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.