x509_cert_store 1.0.0 copy "x509_cert_store: ^1.0.0" to clipboard
x509_cert_store: ^1.0.0 copied to clipboard

A Flutter plugin for Windows desktop applications that enables adding X.509 certificates to the local certificate store.

example/lib/main.dart

import 'dart:convert';
import 'dart:developer';
import 'dart:io';

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

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

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

  void _handleCertificateResult(X509ResValue result) {
    log(result.msg);
    log(result.code);

    if (result.hasError(X509ErrorCode.alreadyExist)) {
      log("Certificate already exists.");
    } else if (result.hasError(X509ErrorCode.canceled)) {
      log("User canceled certificate addition.");
    } else if (!result.isOk) {
      log("Failed to add certificate: ${result.msg}");
    } else {
      log("Certificate added successfully.");
    }
  }

  @override
  Widget build(BuildContext context) {
    final x509CertStorePlugin = X509CertStore();

    const basicKey =
        "MIIDKjCCAhKgAwIBAgIQFSHum2++9bhOXjAo4Z7hZTANBgkqhkiG9w0BAQsFADAaMRgwFgYDVQQDDA93d3cuZXhhbXBsZS5jb20wHhcNMjQwMzI1MDQwMTAxWhcNMjUwMzI1MDQyMTAxWjAaMRgwFgYDVQQDDA93d3cuZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDD95UVvL2GmO1Sq2XEE/m7yK1YzqAlOo68zx8Zk5DS0SmK3e990VtdCPP6cZxcGsJHlqBEg2yMuheC37/tqKdZgRxWbA6DBwZdO9iTSsQigDYi6Ak5YbPSis2z2IJ/RtYnbVM0TZxxwRbPK6zw+evoRAAaVohDzzV3YolHezLacLuIuc8ZX4w+oNBM1nhnYcBxKHeZlIdnrTvnqmUNsc5RsTVgiKuF3JuwqMp8iGK2I5OXKX0PU9Xu2DWDgNDyYFje9cuUd5V80AABQr9QgalOaLkfknluWulOLl8yLhg/icuFQucGnHxNDfDo2eRgxRjMFb53VdLSG8BDfk+7HXDxAgMBAAGjbDBqMA4GA1UdDwEB/wQEAwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEwGgYDVR0RBBMwEYIPd3d3LmV4YW1wbGUuY29tMB0GA1UdDgQWBBTz3vduP0OefbHqptjxpk1V89RpCjANBgkqhkiG9w0BAQsFAAOCAQEAaShA+e6dBaVt9na97fAgGMEdWpfI66WrJOVn5gczcPCzsjtZTkUjKh7IiZHCeyq5vWHmrG20PZpag34vvk0zacwR9PJeCbCzCmGfJ8miKCaywfxRpJVSWweLyppXRk/TDkXynhGAjD0EMHocc6jClcIrypxB9LjoS2oHA/+iGnx6dLeWf9bpTFBDIAevOXpKhlrSftUM1vaPkMdMN/mEk5mx189382IOsH6gocF+ru8u0PnWAdlF3muGsmvF4K31zVS5vMIQLD76FpO7ee/xrOcYxNS+2dPDDs2m9LlWA4BjUJlyfgM39CCRNyxggLrzYzlo1pT/67JOI/57dVa4YQ==";

    /// example certification
    const String certificationBase64Str = basicKey;
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text("Add Certification Example")),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              ElevatedButton(
                  onPressed: () async {
                    final bytes = base64Decode(certificationBase64Str);

                    final file = File(r'C:\Users\User\cert.crt');
                    await file.writeAsBytes(bytes);
                    log("done");
                  },
                  child: const Text("Make Cert file")),
              ElevatedButton(
                onPressed: () async {
                  final rst = await x509CertStorePlugin.addCertificate(
                    storeName: X509StoreName.root,
                    certificateBase64: certificationBase64Str,
                    addType: X509AddType.addNew,
                  );
                  _handleCertificateResult(rst);
                },
                child: const Text("Add_New Certification"),
              ),
              ElevatedButton(
                onPressed: () async {
                  final rst = await x509CertStorePlugin.addCertificate(
                    storeName: X509StoreName.root,
                    certificateBase64: certificationBase64Str,
                    addType: X509AddType.addNewer,
                  );
                  _handleCertificateResult(rst);
                },
                child: const Text("Add_Newer Certification"),
              ),
              ElevatedButton(
                onPressed: () async {
                  final rst = await x509CertStorePlugin.addCertificate(
                    storeName: X509StoreName.root,
                    certificateBase64: certificationBase64Str,
                    addType: X509AddType.addReplaceExisting,
                  );
                  _handleCertificateResult(rst);
                },
                child: const Text("Add ReplaceExisting Certification"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
0
points
303
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for Windows desktop applications that enables adding X.509 certificates to the local certificate store.

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on x509_cert_store

Packages that implement x509_cert_store