firstfloorsoftware / flutter_sodium

Flutter bindings for libsodium
BSD 3-Clause "New" or "Revised" License
102 stars 47 forks source link

Can I use this package to encrypt/decrypt files? #33

Closed phanirithvij closed 4 years ago

phanirithvij commented 4 years ago

Is it possible to encrypt and decrypt files using this package?

ccadieux commented 4 years ago

Yep we do something like this.

 Uint8List enc = await SecretBox.encryptBytes(
      await file.readAsBytes(),
      nonce,
      key,
    );   
  await file.writeAsBytes(<int>[]);
  await file.writeAsBytes(enc);

 Uint8List decryptedBytes = await SecretBox.decryptBytes(
      await file.readAsBytes(),
      nonce,
      key,
    );
phanirithvij commented 4 years ago

I know I can set a custom key but what is nonce could you please clarify?

And what is this line doing?

await file.writeAsBytes(<int>[]);
kozw commented 4 years ago

Please see the official libsodium documentation at https://libsodium.gitbook.io/doc/