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?
CodePudding user response:
You can use encrypt plugin to encrypt strings.
you can do like this for Advanced Encryption Standard (AES):
final plainText = 'YOUR_PASSWORD';
final key = Key.fromUtf8('my 32 length key................');
final iv = IV.fromLength(16);
final encrypter = Encrypter(AES(key));
final encrypted = encrypter.encrypt(plainText, iv: iv);
final decrypted = encrypter.decrypt(encrypted, iv: iv);
print(decrypted); // YOUR_PASSWORD
print(encrypted.base64);// YOUR_ENCRYPTED_STRING
CodePudding user response:
I've used cryptographic hashing functions for Dart and it works fine for me.
The below code is what I used to encrypt 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");
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>