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

outdated

A flutter plugin to encrypt data using elliptic curve keypair.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_elliptic_curve_keypair/flutter_elliptic_curve_keypair.dart';
import 'package:flutter_elliptic_curve_keypair/models/ecc_result_model.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String signed;
  String public;

  /// Encrypt or sign data using ECC
  /// param [dataToSign] the data to be encrypt or sign
  /// [language] should be "en" or "ar"
  /// [alias] ECC keypair alias
  Future<void> ellipticCurveKeyPairSign() async {
    try {
      String dataToSign = "data_to_sign";
      String language = "English";
      String alias = "your_alias_name";

      EccResultModel signedData =
          await FlutterEllipticCurveKeyPair.ellipticCurveKeyPairSigning(
        message: dataToSign,
        language: language,
        alias: alias,
      );
      if (signedData.success) {
        setState(() {
          signed = "SUCCEESS, SIGNED DATA HERE => ${signedData.data}";
        });
      } else {
        setState(() {
          public = "FAILED, ERROR => ${signedData.data.toString()}";
        });
      }
    } on PlatformException catch (e) {
      print("Unexpected error occured$e");
    }
  }

  /// Get the public key
  /// can be used in [validate] the signed data
  Future<void> ellipticCurveKeyPairPublicKey() async {
    try {
      EccResultModel publicKey =
          await FlutterEllipticCurveKeyPair.ellipticCurveKeyPairPublicKey();
      if (publicKey.success) {
        setState(() {
          public = "SUCCEESS, PUBLIC KEY HERE => ${publicKey.data}";
        });
      } else {
        setState(() {
          signed = "FAILED, ERROR => ${publicKey.data.toString()}";
        });
      }
    } on PlatformException catch (e) {
      print("Unexpected error occured$e");
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text(''),
        ),
        body: Column(
          children: [
            Center(
              child: RaisedButton(
                child: Text('Sign data'),
                onPressed: () => ellipticCurveKeyPairSign(),
              ),
            ),
            Text(signed != null ? signed : ""),
            Center(
              child: RaisedButton(
                child: Text('Get public key'),
                onPressed: () => ellipticCurveKeyPairPublicKey(),
              ),
            ),
            Text(public != null ? public : ""),
          ],
        ),
      ),
    );
  }
}
1
likes
0
points
23
downloads

Publisher

unverified uploader

Weekly Downloads

A flutter plugin to encrypt data using elliptic curve keypair.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flutter_elliptic_curve_keypair