Search code examples
fluttersqlitedartpassword-encryptionsqflite

How to encrypt password while saving in database in Flutter-SQLite-Dart application?


I'm developing a mobile application using Flutter, Dart and SQLite. It is just a Login page validation kind of project where I need to encrypt the password and user's personal details while inserting in the database. At least I want the password to be encrypted. How is it possible to achieve this?


Solution

  • I've used cryptographic hashing functions for Dart and it works fine for me.

    The below code is what I used to hash the password.

    import 'package:crypto/crypto.dart';
    import 'dart:convert'; // for the utf8.encode method
    
    void main() {
      var bytes = utf8.encode("password"); // data being hashed
    
      var digest = sha256.convert(bytes);
    
      print("Digest as bytes: ${digest.bytes}");
      print("Digest as hex string: $digest");
    }