dio-http-cache
dio-http-cache copied to clipboard
Any example on cipher to encrypt cache?
Could add an example on this config usage? thanks!
final options = const CacheOptions( store: MemCacheStore(), policy: CachePolicy.request, hitCacheOnErrorExcept: [401, 403], maxStale: const Duration(days: 7), priority: CachePriority.normal, cipher: null, keyBuilder: CacheOptions.defaultCacheKeyBuilder, allowPostMethod: false, );
Anybody can explain an example for encrypt/decrypt?
I got this..
import 'dart:typed_data';
import 'package:encrypt/encrypt.dart';
import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
main() {
final key = Key.fromUtf8('my32lengthsupersecretnooneknows1'); // Just example
final iv = IV.fromLength(16);
final encrypter = Encrypter(AES(key));
final cacheConfig = CacheConfig(
/// ...
encrypt: (bytes) async {
return encrypter.encryptBytes(bytes, iv: iv).bytes;
},
decrypt: (bytes) async {
return encrypter.decryptBytes(
Encrypted(Uint8List.fromList(bytes)),
iv: iv,
);
},
);
}