native_armor_vault 0.0.1
native_armor_vault: ^0.0.1 copied to clipboard
Native secure storage for Flutter. Encrypts secrets using XOR and stores them in C++ native layer, making them harder to extract through reverse engineering.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:native_armor_vault/native_armor_vault.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Native Armor Vault Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final List<SecretItem> _secrets = [];
bool _isLoading = false;
String? _error;
@override
void initState() {
super.initState();
_loadSecrets();
}
Future<void> _loadSecrets() async {
setState(() {
_isLoading = true;
_error = null;
});
try {
// Attempt to load secrets from the vault
// Note: This will only work after running `dart run native_armor_vault:generate`
final secrets = <SecretItem>[
SecretItem(name: 'API_KEY', getValue: () => ArmorVault.api_key),
SecretItem(
name: 'DATABASE_URL',
getValue: () => ArmorVault.database_url,
),
SecretItem(
name: 'SECRET_TOKEN',
getValue: () => ArmorVault.secret_token,
),
SecretItem(
name: 'AWS_ACCESS_KEY',
getValue: () => ArmorVault.aws_access_key,
),
SecretItem(name: 'STRIPE_KEY', getValue: () => ArmorVault.stripe_key),
];
setState(() {
_secrets.clear();
_secrets.addAll(secrets);
_isLoading = false;
});
} catch (e) {
setState(() {
_error = e.toString();
_isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('🔐 Native Armor Vault'),
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: _loadSecrets,
tooltip: 'Reload Secrets',
),
],
),
body: _buildBody(),
);
}
Widget _buildBody() {
if (_isLoading) {
return const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(height: 16),
Text('Loading secrets from native vault...'),
],
),
);
}
if (_error != null) {
return Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, size: 64, color: Colors.red),
const SizedBox(height: 16),
const Text(
'Failed to load secrets',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Text(
_error!,
textAlign: TextAlign.center,
style: const TextStyle(color: Colors.red),
),
const SizedBox(height: 24),
const Text(
'Make sure you have:\n'
'1. Created native_vault.yaml\n'
'2. Run: dart run native_armor_vault:generate\n'
'3. Rebuilt the app',
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: _loadSecrets,
child: const Text('Retry'),
),
],
),
),
);
}
if (_secrets.isEmpty) {
return const Center(
child: Padding(
padding: EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.lock_outline, size: 64, color: Colors.grey),
SizedBox(height: 16),
Text(
'No secrets configured',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
SizedBox(height: 8),
Text(
'Create native_vault.yaml and run the generator',
textAlign: TextAlign.center,
),
],
),
),
);
}
return ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: _secrets.length,
itemBuilder: (context, index) {
return SecretCard(secret: _secrets[index]);
},
);
}
}
class SecretItem {
final String name;
final String Function() getValue;
SecretItem({required this.name, required this.getValue});
}
class SecretCard extends StatefulWidget {
final SecretItem secret;
const SecretCard({super.key, required this.secret});
@override
State<SecretCard> createState() => _SecretCardState();
}
class _SecretCardState extends State<SecretCard> {
bool _isRevealed = false;
String? _value;
String? _error;
void _toggleReveal() {
setState(() {
if (!_isRevealed) {
try {
_value = widget.secret.getValue();
_error = null;
} catch (e) {
_error = e.toString();
}
}
_isRevealed = !_isRevealed;
});
}
@override
Widget build(BuildContext context) {
return Card(
margin: const EdgeInsets.only(bottom: 12),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.key, color: Colors.deepPurple),
const SizedBox(width: 8),
Expanded(
child: Text(
widget.secret.name,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
IconButton(
icon: Icon(
_isRevealed ? Icons.visibility_off : Icons.visibility,
),
onPressed: _toggleReveal,
tooltip: _isRevealed ? 'Hide' : 'Reveal',
),
],
),
if (_isRevealed) ...[
const Divider(),
if (_error != null)
Text(
'Error: $_error',
style: const TextStyle(color: Colors.red),
)
else
Container(
width: double.infinity,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(8),
),
child: SelectableText(
_value ?? '',
style: const TextStyle(
fontFamily: 'monospace',
fontSize: 14,
),
),
),
],
],
),
),
);
}
}