secret_db 1.1.0 copy "secret_db: ^1.1.0" to clipboard
secret_db: ^1.1.0 copied to clipboard

A Flutter package for secure encrypted database storage

secret_db #

secret_db is a Flutter package that allows secure and encrypted data storage using an SQLite database. It provides a convenient way to store sensitive data with encryption and protection against data extraction on rooted/jailbroken devices.

Purpose #

This package was developed to provide secure data storage in Flutter by using SHA-256 encryption to protect information in the database. It offers:

  • Encryption of data before storing it in the SQLite database.
  • Protection against data extraction on rooted/jailbroken devices.
  • Support for storing simple data (like String) or objects (like serialized classes).

Example Initialization: #

import 'package:encrypted_db_storage/encrypted_db_storage.dart';

void main() async {
  // Initialize the database with custom parameters
  await SecretDB.init(
    dbName: "secure_data.db",  // Database name
    tableName: "secure_info",  // Table name
    key: "super_secure_key",   // Encryption key
  );
}

1.0 Usage Example with Simple Data #

void saveUserToken() async {
  await SecretDB.saveData('user_token', 'my_secure_token');
}

1.1 Retrieve Data #

void getUserToken() async {
  String? token = await SecretDB.getData('user_token');
  print('Token retrieved: $token');
}

2.0 Usage Example with Objects #

class User {
  final String username;
  final String email;

  User({required this.username, required this.email});

  // Converts the object to a map (for serialization)
  Map<String, dynamic> toJson() {
    return {
      'username': username,
      'email': email,
    };
  }

  // Converts the map back to an object
  factory User.fromJson(Map<String, dynamic> json) {
    return User(
      username: json['username'],
      email: json['email'],
    );
  }
}

2.1 Save Object (Serialization): #

import 'package:encrypted_db_storage/encrypted_db_storage.dart';

void saveUser() async {
  User user = User(username: 'john_doe', email: 'john@example.com');
  
  // Serialize the object to a JSON String
  String serializedUser = SecretDB._serialize(user);
  
  // Save the object in the database
  await SecretDB.saveData('user_info', serializedUser);
}

2.2 Retrieve Object (Deserialization): #

import 'package:encrypted_db_storage/encrypted_db_storage.dart';

void getUser() async {
  // Retrieve the stored user
  String? userJson = await SecretDB.getData('user_info');
  
  if (userJson != null) {
    // Deserialize the object
    User user = SecretDB._deserialize(userJson, (json) => User.fromJson(json));
    
    print('Username: ${user.username}, Email: ${user.email}');
  }
}

3. Delete Data #

If you want to securely delete data, you can use the deleteData method.

await SecretDB.deleteData('user_token');

4. Close the Database #

await SecretDB.closeDB();
2
likes
0
points
34
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for secure encrypted database storage

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

crypto, encrypt, flutter, path, sqflite

More

Packages that depend on secret_db