encryptify 0.0.4 copy "encryptify: ^0.0.4" to clipboard
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 #

  1. When a user signs up, we generate RSA Key Pairs, AES Key, and IV using:

    await Encryptify.generateKeys();
    
  2. Retrieve the RSA Public Key using:

    await Encryptify.returnKeys();
    

    The public key is then stored in Firebase.

  3. 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.
  4. The encrypted AES Key, IV, and RSA Private Key are uploaded to Firestore.

πŸ” Encrypting Messages #

To send an encrypted message to User B:

  1. Use the package method:

    await Encryptify.encryptMessage(
        message: message,
        recipientRSAPublicKey: recipientPublicKey,
    );
    

    This returns:

    • The encrypted message
    • The encrypted AES Key
    • The encrypted IV
  2. The AES Key and IV are encrypted using User B’s RSA Public Key.

  3. 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:

  1. Retrieve the creationTime (Email & Password), sub/id (Google), or ID (Facebook).
  2. Retrieve the encrypted AES Key, IV, RSA Private Key, and Public Key from Firestore.
  3. Decrypt these using:
    await Encryptify.decryptionWithCustomString(
        pemRSAPublicKey: userDoc["rsaPublicKey"],
        encryptedRsaPrivateKey: userDoc["encryptedRsaPrivateKey"],
        encryptedAesKey: userDoc["encryptedAESKey"],
        encryptedIv: userDoc["encryptedIV"],
        customString: _auth.currentUser!.metadata.creationTime.toString(),
    );
    
    This ensures that even if the user clears app data, the keys can be recovered.

❗ 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

KAMESH SINGH
Flutter Developer

GitHub LinkedIn

Copyright Β© 2024 Kamesh Singh Sisodiya. Licensed under the MIT LICENSE

1
likes
150
points
26
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for end-to-end encryption using hybrid RSA/AES cryptography

Repository (GitHub)
View/report issues

Topics

#encryption #security #end-to-end-encryption #data-protection #data-privacy

Documentation

API reference

License

MIT (license)

Dependencies

crypto, encrypt, flutter, flutter_secure_storage, pointycastle, rsa_encrypt

More

Packages that depend on encryptify