fcg_network_interceptor 0.0.2
fcg_network_interceptor: ^0.0.2 copied to clipboard
A Dio interceptor that automatically encrypts request bodies using the encrypt_secure package.
FCG Network Interceptor (fcg_network_interceptor) #
A Dio interceptor that automatically encrypts request bodies using sodium_libs (ChaCha20-Poly1305).
Features #
- Automatic Encryption: Intercepts
POST,PUT, andPATCHrequests and automatically encrypts the JSON body. - Request Wrapping: Wraps the encrypted string in a standardized JSON structure:
{"request": "ENCRYPTED_STRING"}. - Selective Encryption: Provides a mechanism to skip encryption for specific requests (e.g., standard
application/x-www-form-urlencodedsubmissions). - Error Handling: Catches encryption errors and wraps them in
DioExceptionfor consistent error handling.
Installation #
Add the following to your pubspec.yaml:
dependencies:
fcg_network_interceptor: ^0.0.1
dio: ^5.0.0
sodium_libs: ^3.4.6+4
Usage #
1. Initialization #
Add the EncryptionInterceptor to your Dio instance. You must provide a base64-encoded key.
import 'package:dio/dio.dart';
import 'package:fcg_network_interceptor/fcg_network_interceptor.dart';
void main() {
final dio = Dio();
// Create a 32-byte key, base64 encoded
const myBase64Key = 'YOUR_BASE64_ENCODED_32_BYTE_KEY';
// Add the interceptor to the chain
dio.interceptors.add(EncryptionInterceptor(base64Key: myBase64Key));
}
2. Making Encrypted Requests #
By default, any POST, PUT, or PATCH request with a JSON body (Map<String, dynamic>) will be encrypted.
// This request body will be automatically encrypted
final response = await dio.post(
'/api/secure-endpoint',
data: {
'userId': '12345',
'action': 'update_profile'
},
);
What happens over the network: The body sent to the server will look like:
{
"request": "U2FsdGVkX1+..."
}
3. Skipping Encryption #
If you need to send a request without encryption (e.g., for application/x-www-form-urlencoded or public endpoints), use the skipEncryption option in extra.
final response = await dio.post(
'/api/public-endpoint',
data: {
'grant_type': 'password',
'username': 'user',
'password': 'password'
},
options: Options(
contentType: Headers.formUrlEncodedContentType,
extra: {
'skipEncryption': true, // Disables the interceptor for this request
},
),
);
Dependencies #
- dio: A powerful Http client for Dart.
- sodium_libs: Libsodium for Dart.
License #
MIT License. See LICENSE for details.
Copyright (c) 2026 Fakeeh Tech.