encryptify 0.0.4
encryptify: ^0.0.4 copied to clipboard
A Flutter package for end-to-end encryption using hybrid RSA/AES cryptography
π Encryptify #
A Flutter package for end-to-end encryption using hybrid RSA/AES cryptography. Secure your messages, files, and data with minimal setup. Perfect for chat apps and sensitive data transfer.
π₯ Installation #
Add the following to your pubspec.yaml
file:
dependencies:
encryptify: ^1.0.0
Or install it via the command line:
flutter pub add encryptify
π Encryptify Implementation Guide #
π Overview #
This guide explains the actual encryption and decryption process used in the application.
π User Sign-Up Process #
-
When a user signs up, we generate RSA Key Pairs, AES Key, and IV using:
await Encryptify.generateKeys();
-
Retrieve the RSA Public Key using:
await Encryptify.returnKeys();
The public key is then stored in Firebase.
-
Encrypt the AES Key, IV, and RSA Private Key using a custom string:
- If using Firebase Email & Password authentication, we use the account creation date.
- If using Google OAuth, we use the sub/id from the user credentials.
- If using Facebook Auth, we use the ID from the user credentials.
-
The encrypted AES Key, IV, and RSA Private Key are uploaded to Firestore.
π Encrypting Messages #
To send an encrypted message to User B:
-
Use the package method:
await Encryptify.encryptMessage( message: message, recipientRSAPublicKey: recipientPublicKey, );
This returns:
- The encrypted message
- The encrypted AES Key
- The encrypted IV
-
The AES Key and IV are encrypted using User Bβs RSA Public Key.
-
These three components (encrypted message, AES Key, and IV) are sent to User B.
π Decrypting Messages #
User B decrypts the received message using:
await Encryptify.decryptMessage(
currentUserID: _auth.currentUser!.uid,
senderID: senderID,
encryptedMessage: encryptedMessage,
recipientencryptedAESKey: encryptedAESKey,
recipientencryptedIV: encryptedIV,
);
π User Login Process #
When a user logs in:
- Retrieve the creationTime (Email & Password), sub/id (Google), or ID (Facebook).
- Retrieve the encrypted AES Key, IV, RSA Private Key, and Public Key from Firestore.
- Decrypt these using:
This ensures that even if the user clears app data, the keys can be recovered.await Encryptify.decryptionWithCustomString( pemRSAPublicKey: userDoc["rsaPublicKey"], encryptedRsaPrivateKey: userDoc["encryptedRsaPrivateKey"], encryptedAesKey: userDoc["encryptedAESKey"], encryptedIv: userDoc["encryptedIV"], customString: _auth.currentUser!.metadata.creationTime.toString(), );
β Handling Key Loss After Data Clear #
The RSA Private Key is stored in Flutter Secure Storage. If the user clears the app data or reinstalls, new keys will be generated, making the stored RSA Public Key incompatible with the new Private Key.
To prevent this, we store the encrypted Private Key in Firestore and decrypt it upon login.
π Signing Out #
When a user signs out, clear keys from Flutter Secure Storage using:
await Encryptify.flushKeys();
π Security Considerations #
- Store your Firebase configuration securely
- Implement proper authentication before allowing key recovery
- Consider adding an additional authentication factor before decrypting sensitive keys
- Regularly rotate keys for enhanced security
π Devloper Info & License #
KAMESH SINGH
Flutter Developer
Copyright Β© 2024 Kamesh Singh Sisodiya. Licensed under the MIT LICENSE