Skip to content

Commit

Permalink
release file encryption (Relates to #114, #52, #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skycoder42 committed Aug 18, 2024
1 parent 7c8a78f commit 8a1bcea
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/sodium/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.2.0] - 2024-08-18
### Added
- Added `crypto.secretStream.pushChunked` and `crypto.secretStream.pullChunked`
- Serve as a replacement for the deprecated `push` and `pull` APIs
- Allow for a secure and bug-free encryption of files and other binary streams
by requiring a `chunkSize` that is used to partition the incoming binary
data into fix-sized chunks, just as the API expects.
- Added file encryption/decryption example

### Deprecated
- Deprecated `crypto.secretStream.push` and `crypto.secretStream.pull`
- These methods where error prone and hard to use, as the API assumes that
the stream events are pre-chunked and "separate" from each other, while
`Stream<List<int>>` in dart typically means an "arbitrary binary stream"
- Use `pushChunked` and `pullChunked` as replacement
- Related: #114, #52, #26

## [3.1.0] - 2024-08-15
### Fixed
- Added override for SodiumSumo.runIsolated that passes a SodiumSumo instance to the callback (#116)
Expand Down Expand Up @@ -210,6 +227,7 @@ changed, only the name of the getter. (#61)
### Added
- Initial stable release

[3.2.0]: https://github.com/Skycoder42/libsodium_dart_bindings/compare/sodium-v3.1.0...sodium-v3.2.0
[3.1.0]: https://github.com/Skycoder42/libsodium_dart_bindings/compare/sodium-v3.0.1...sodium-v3.1.0
[3.0.1]: https://github.com/Skycoder42/libsodium_dart_bindings/compare/sodium-v3.0.0...sodium-v3.0.1
[3.0.0]: https://github.com/Skycoder42/libsodium_dart_bindings/compare/sodium-v2.3.1+1...sodium-v3.0.0
Expand Down
32 changes: 32 additions & 0 deletions packages/sodium/example/lib/sodium_example.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ignore_for_file: avoid_print, public_member_api_docs
import 'dart:io';
import 'dart:typed_data';

import 'package:sodium/sodium.dart';
Expand Down Expand Up @@ -26,3 +27,34 @@ Uint8List runSample(Sodium sodium, String message) {
secretKey.dispose();
}
}

Future<void> simpleFileEncryption(
Sodium sodium,
String plain,
String cipher,
) async {
const chunkSize = 4096;
final secretKey = sodium.crypto.secretStream.keygen();

// encryption
await sodium.crypto.secretStream
.pushChunked(
messageStream: File(plain).openRead(),
key: secretKey,
chunkSize: chunkSize,
)
.pipe(
File(cipher).openWrite(),
);

// decryption
await sodium.crypto.secretStream
.pushChunked(
messageStream: File(cipher).openRead(),
key: secretKey,
chunkSize: chunkSize,
)
.pipe(
File(plain).openWrite(),
);
}
2 changes: 1 addition & 1 deletion packages/sodium/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: sodium
description: Dart bindings for libsodium, for the Dart-VM and for the Web
version: 3.1.0
version: 3.2.0
homepage: https://github.com/Skycoder42/libsodium_dart_bindings

environment:
Expand Down

0 comments on commit 8a1bcea

Please sign in to comment.