Sample code for 30+ languages & platforms
Dart

Import a Certificate (.cer file) into a Windows Certificate Store

See more Certificates Examples

Demonstrates how to import a certificate (without private key) into a Windows certificate store.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  final cert = CkCert();

  try {
    cert.loadFromFile('qa_data/certs/example.cer');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final certStoreCU = CkCertStore();
  final readOnlyFlag = false;

  // "CurrentUser" and "My" are the exact keywords to select your user account's certificate store.
  try {
    certStoreCU.openWindowsStore('CurrentUser', 'My', readOnlyFlag);
  } on ChilkatException {
    print('Failed to open the CurrentUser/My certificate store for read/write.');
    return;
  }

  // Import the certificate into the CurrentUser/My certificate store.
  try {
    certStoreCU.addCertificate(cert);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('Imported ${cert.subjectCN}');
  print('Success.');
}