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

PKCS#11 FFI Wrapper for Dart

example/dpkcs11_example.dart

import 'dart:convert';

import 'package:dpkcs11/dpkcs11.dart';
import 'package:dpkcs11/src/digester_type.dart';

void main(List<String> arguments) {
  // String libraryPath = 'C:\\Windows\\System32\\akisp11.dll';
  String libraryPath = 'C:\\SoftHSM2\\lib\\softhsm2-x64.dll';

  Dpkcs11 dpkcs11 = Dpkcs11(libraryPath: libraryPath);
  dpkcs11.digester = DigesterType.hardware;
  // Utils.logLevel = Level.debug;

  try {
    PKCS11Session session = dpkcs11.init().selectFirstSlot().openSession();
    try {
      session.login("123456");
      try {
        List<int> hash = session.digest(DigestMethod.SHA_1, "welcome1");
        print("Digest: $hash");

        PKCS11Keypair? kp = session.getKeyPairByAttribute(
          PKCS11Attribute.SIGN,
          true,
        );

        if (kp == null) {
          throw Exception("No Key Found for Signing");
        }

        String datatosign = "Hello World!";

        List<int> signature = kp.sign(datatosign);
        print("Signature value: ${base64.encode(signature)}");

        bool signatureResult = kp.verify(datatosign, signature);
        print("Verify signature: $signatureResult");
      } finally {
        session.logout();
      }
    } finally {
      session.close();
    }
  } catch (e) {
    print("Error: $e");
  } finally {
    dpkcs11.close();
  }
  print("bye bye");
}
0
likes
150
points
26
downloads

Publisher

verified publisherdevinim.gen.tr

Weekly Downloads

PKCS#11 FFI Wrapper for Dart

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

asn1lib, collection, crypto, ffi, logger, path, pointycastle, x509

More

Packages that depend on dpkcs11