bouncy_castle_security 0.0.4 copy "bouncy_castle_security: ^0.0.4" to clipboard
bouncy_castle_security: ^0.0.4 copied to clipboard

A robust encryption and decryption utility implementing AES, SHA-1, and MD5 algorithms using Bouncy Castle for secure data handling and password generation.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:bouncy_castle_security/bouncy_castle_security.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Bouncy Castle Security",
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
        useMaterial3: true,
      ),
      home: const EncryptionDemo(),
    );
  }
}

class EncryptionDemo extends StatefulWidget {
  const EncryptionDemo({super.key});

  @override
  State<EncryptionDemo> createState() => _EncryptionDemoState();
}

class _EncryptionDemoState extends State<EncryptionDemo> {
  final BouncyCastleSecurity _bouncyCastleSecurity =
      BouncyCastleSecurity.instance;
  final Map<String, String> _results = {};

  @override
  void initState() {
    super.initState();
    _initializeResults();
  }

  Future<void> _initializeResults() async {
    try {
      // Encrypt
      final encryptedString =
          await _bouncyCastleSecurity.encrypt(data: "hello", password: "123");

      // Decrypt
      final decryptedString = await _bouncyCastleSecurity.decrypt(
          encryptedData: encryptedString, password: "123");

      // Create Password
      const masterKey = "TestMasterKey";
      const index = 1;
      const order = "0123";
      final createdPassword = await _bouncyCastleSecurity.createPassword(
        masterKey: masterKey,
        index: index,
        order: order,
      );

      // Generate Index
      final generatedIndex = await _bouncyCastleSecurity.generateIndex();

      // Generate SHA1 Hash
      final sha1HashString =
          await _bouncyCastleSecurity.generateSHA1HashValue(data: "hello");

      // Encrypt Data MD5
      final encryptedDataMD5 =
          await _bouncyCastleSecurity.encryptDataMD5(data: "hello");

      setState(() {
        _results.addAll({
          "Encrypt": encryptedString,
          "Decrypt": decryptedString,
          "Create Password": createdPassword,
          "Generate Index": generatedIndex.toString(),
          "SHA1 Hash": sha1HashString,
          "MD5 Hash": encryptedDataMD5,
        });
      });
    } catch (e) {
      setState(() {
        _results["Error"] = e.toString();
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: const Text("Bouncy Castle Security"),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(16),
        child: _buildResultsSection(),
      ),
    );
  }

  Widget _buildResultsSection() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: _results.entries.map((entry) {
        return Card(
          margin: const EdgeInsets.only(bottom: 16),
          child: Padding(
            padding: const EdgeInsets.all(10),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Icon(
                      _getIconForOperation(entry.key),
                      color: Theme.of(context).colorScheme.primary,
                    ),
                    const SizedBox(width: 8),
                    Text(
                      entry.key,
                      style: const TextStyle(
                        fontSize: 16,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ],
                ),
                const SizedBox(height: 8),
                Container(
                  width: double.infinity,
                  padding: const EdgeInsets.all(12),
                  decoration: BoxDecoration(
                    color: Colors.grey[100],
                    borderRadius: BorderRadius.circular(8),
                  ),
                  child: Text(
                    entry.value,
                    style: TextStyle(
                      fontFamily: "monospace",
                      fontSize: 13,
                      color: Colors.grey[800],
                    ),
                  ),
                ),
              ],
            ),
          ),
        );
      }).toList(),
    );
  }

  IconData _getIconForOperation(String operation) {
    switch (operation) {
      case "Encrypt":
        return Icons.lock;
      case "Decrypt":
        return Icons.lock_open;
      case "Create Password":
        return Icons.key;
      case "Generate Index":
        return Icons.numbers;
      case "SHA1 Hash":
      case "MD5 Hash":
        return Icons.tag;
      default:
        return Icons.security;
    }
  }
}
1
likes
160
points
17
downloads

Publisher

unverified uploader

Weekly Downloads

A robust encryption and decryption utility implementing AES, SHA-1, and MD5 algorithms using Bouncy Castle for secure data handling and password generation.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on bouncy_castle_security

Packages that implement bouncy_castle_security