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,

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      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.