commonName property

String? get commonName

Returns the Common Name (CN) extracted from the certificate's subject Distinguished Name, or null if no CN is present.

Example: For a subject of CN=Example Root CA, O=Example Org, C=US, this returns Example Root CA.

Note: The CN is primarily useful as a human-readable label. For TLS server certificates, the Subject Alternative Name (SAN) extension is the authoritative source for hostnames.

Implementation

String? get commonName {
  final match = RegExp(r'CN=([^,]+)').firstMatch(_subject);
  return match?.group(1)?.trim();
}