Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Easy to sync with back end server #7

Closed
leedstyh opened this issue Jul 31, 2019 · 10 comments
Closed

[Feature Request] Easy to sync with back end server #7

leedstyh opened this issue Jul 31, 2019 · 10 comments

Comments

@leedstyh
Copy link

leedstyh commented Jul 31, 2019

Hi,

Hive is great, and I wanna use it in a mobile-first offline-first app. So I have to sync data with my back-end server silently.

My app will encrypt user data and since Hive already does it, the best way is sync the encrypted string(or what ever binary format) to the server. So I need a method to get this encrypted string.

Maybe additional methods like Future<void> putRaw(String k, String v) and Future<String> getRaw(String k) are good choice?

@simc
Copy link
Member

simc commented Jul 31, 2019

Hi,
Do want to backup a box or do you want to decrypt and use the data on the server?

Every encrypted entry also contains an IV without that, the entry cannot be decrypted.

What would putRaw() and getRaw() do exactly? And what would getRaw() return for other objects?

@leedstyh
Copy link
Author

Hi,

I wanna backup the whole box, incrementally. Say I have 10 items total in the box now, after changing one item (box.put('myDog', dog)), I sync it to the server right away. Or one item changed on the server, I need to sync the changed one to the client app.

I wanna encrypt the user data both on client app and server, and since Hive already encrypt data, I think reuse it is a good idea.

So what transferred between client app and server is NOT dog, but the dog after encrypted. I'm not sure but I assume it's a String("xxxooo") stored on the storage after dog encrypted.

Future<String> box.getRaw("myDog") returns that String("xxxooo") and I sync this String("xxxooo") to the server.

Future<void> putRaw("myDog", "xxxooo from server") save the change from the server directly.

Sorry that I'm not good at English.

@simc
Copy link
Member

simc commented Jul 31, 2019

Okay I understand... The problem is that Hive stores objects as Uint8List when running in the vm. In the browser, only non primitive and encrypted values are stored as Uint8List. I don't know what getRaw() should return. A string is impossible because of the IV.

I think the best way is to transfer the data unencrypted over HTTPS and handle encryption on the server (maybe even with another Hive ;).

You would have to sync the value, the IV and the encryption key otherwise.

Edit: You can implement your sync logic using watch()

@leedstyh
Copy link
Author

I got it. But encrypt and decrypt both on client and server will waste too much CPU :(

I can encrypt the data to a string by myself, and save this string in hive(box.put("myDog", "encrypted string")). And I register a TypeAdapter say LongString for it in case the encrypted string is too long.

Do you think it is a good idea?

@simc
Copy link
Member

simc commented Jul 31, 2019

Sure you can do that but unless you change the data very often I would not worry about CPU usage. The AES algorithm Hive uses is quite fast.

@leedstyh
Copy link
Author

Thanks @leisim I'll double think how to design my app

@ThinkDigitalSoftware
Copy link

Won't transferring it unencrypted leave you vulnerable for mitm attacks?

@adriancmurray
Copy link

@ThinkDigitalSoftware this is why @leisim specified transferring over HTTPS to encrypt over the channels. The encryption here is so those who have direct access to the data can not read it (such as us developers) unless trusted.

@ThinkDigitalSoftware
Copy link

Oh that makes sense.

@jamesdixon
Copy link

@adriancmurray what approach did you end up taking? looking to rebuild my app and it definitely needs to be offline-first so im exploring options for persistence, including hive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants