readP12CertificateInfo function

P12CertificateInfo readP12CertificateInfo(
  1. File certificate, {
  2. String? password,
})

Extracts certificate information from a P12 (PKCS#12) certificate file.

Uses OpenSSL to read the certificate and extract the friendly name and local key ID. Automatically handles legacy Apple certificates by retrying with the -legacy flag if needed.

The optional password is used to decrypt the certificate (defaults to empty string).

Throws when OpenSSL fails to read the certificate.

Implementation

P12CertificateInfo readP12CertificateInfo(
  File certificate, {
  String? password,
}) {
  final certInfo = _opensslPkcs12(certificate, password: password);

  final friendlyNameRegEx = RegExp('friendlyName: (.*)');
  final friendlyName = friendlyNameRegEx.firstMatch(certInfo)?.group(1);
  final localKeyIDRegEx = RegExp('localKeyID: (.*)');
  final localKeyID = localKeyIDRegEx.firstMatch(certInfo)?.group(1);
  return P12CertificateInfo(
    friendlyName: friendlyName!,
    localKeyId: localKeyID!,
  );
}