Skip to content

Commit

Permalink
Merge pull request #847 from juliansteenbakker/improvement/web
Browse files Browse the repository at this point in the history
Improvement/web
  • Loading branch information
juliansteenbakker authored Jan 4, 2025
2 parents e2c1b97 + 1079868 commit e804133
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@ We welcome contributions to this project! To set up your workspace after cloning
1. Fetch the Flutter dependencies:
`flutter pub get`

2. Bootstrap the workspace with `melos`:
2. Activate `melos`:
`dart pub global activate melos`

3. (Optional) Add pub executables to your path:
`export PATH="$PATH":"$HOME/.pub-cache/bin"`

4. Bootstrap the workspace with `melos`:
`melos bootstrap`

This will prepare the project for development by linking and configuring all required dependencies.
Expand Down
59 changes: 29 additions & 30 deletions flutter_secure_storage_web/lib/flutter_secure_storage_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ library flutter_secure_storage_web;
import 'dart:convert';
import 'dart:js_interop' as js_interop;
import 'dart:js_interop_unsafe' as js_interop;
import 'dart:typed_data';

import 'package:flutter/foundation.dart';
import 'package:flutter_secure_storage_platform_interface/flutter_secure_storage_platform_interface.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:web/web.dart' as web;
Expand Down Expand Up @@ -63,10 +63,9 @@ class FlutterSecureStorageWeb extends FlutterSecureStoragePlatform {
}
}

/// Encrypts and saves the [key] with the given [value].
/// Reads and decrypts the value for the given [key].
///
/// If the key was already in the storage, its associated value is changed.
/// If the value is null, deletes associated value for the given [key].
/// Returns null if the key does not exist or if decryption fails.
@override
Future<String?> read({
required String key,
Expand Down Expand Up @@ -231,40 +230,40 @@ class FlutterSecureStorageWeb extends FlutterSecureStoragePlatform {
String? cypherText,
Map<String, String> options,
) async {
if (cypherText == null) {
return null;
}
if (cypherText != null) {
try {
final parts = cypherText.split(".");

final parts = cypherText.split(".");
final iv = base64Decode(parts[0]);
final algorithm = _getAlgorithm(iv);

final iv = base64Decode(parts[0]);
final algorithm = _getAlgorithm(iv);
final decryptionKey = await _getEncryptionKey(algorithm, options);

final decryptionKey = await _getEncryptionKey(algorithm, options);
final value = base64Decode(parts[1]);

final value = base64Decode(parts[1]);
final decryptedContent = await web.window.crypto.subtle
.decrypt(
_getAlgorithm(iv),
decryptionKey,
Uint8List.fromList(value).toJS,
)
.toDart;

final decryptedContent = await web.window.crypto.subtle
.decrypt(
_getAlgorithm(iv),
decryptionKey,
Uint8List.fromList(value).toJS,
)
.toDart;
final plainText = utf8.decode(
(decryptedContent! as js_interop.JSArrayBuffer).toDart.asUint8List(),
);

final plainText = utf8.decode(
(decryptedContent! as js_interop.JSArrayBuffer).toDart.asUint8List(),
);
return plainText;
} catch (e, s) {
if (kDebugMode) {
print(e);
debugPrintStack(stackTrace: s);
}
}
}

return plainText;
return null;
}

// @override
// Future<bool> isCupertinoProtectedDataAvailable() => Future.value(false);
//
// @override
// Stream<bool> get onCupertinoProtectedDataAvailabilityChanged =>
// Stream.empty();
}

extension on List<String> {
Expand Down

0 comments on commit e804133

Please sign in to comment.