Extraction of the Brazilian ICP-Brasil identifiers from a certificate.
The value of the natural-person otherName (OID 2.16.76.1.3.1) is not
a CPF: it is a positional block defined by DOC-ICP-04.
25101982 | 09498269793 | 00000000000 | 000000000000000 | SSPDF
-------- ----------- ----------- --------------- -----
birthdate CPF NIS/PIS ID card number issuer
(DDMMYYYY) (11 digits) (11 digits) (15 digits) (6 chars)
The CPF sits at [8, 19). Two tempting approaches are wrong:
substring(0, 11)yields25101982094(birth date + 3 CPF digits);- "first 11-digit window with valid check digits" is ambiguous — a block can hold several windows that pass the check-digit maths, and a birth date can itself start a valid one. Only the official offset is trustworthy.
The order recommended by the standard is to look first at the serialNumber
attribute of the Subject DN (OID 2.5.4.5), which carries the CPF/CNPJ
directly and is the current form; the positional block is compatibility,
kept until 2028-12-31.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
extractBirthDate(
String? naturalPersonBlock) → DateTime? -
Birth date stored in the first 8 digits (DDMMYYYY) of the natural-person
block, or
nullwhen missing or invalid. -
extractCnpj(
{String? subjectDn, String? otherNameCnpj}) → String? -
Extracts the CNPJ (14 digits) from the DN
serialNumberor from the oidCnpjotherName. Returnsnullwhen absent or when the check digits do not match. -
extractCpf(
{String? subjectDn, String? otherNameNaturalPerson, String? otherNameResponsible}) → String? - Extracts the CPF in the order recommended by the standard:
-
extractCpfFromBlock(
String? value) → String? - Extracts the CPF from a natural-person positional block.
-
extractIdCard(
String? naturalPersonBlock) → String? -
ID card number (RG) stored at
[30, 45)of the natural-person block. -
extractNis(
String? naturalPersonBlock) → String? -
NIS/PIS/PASEP stored at
[19, 30)of the natural-person block. -
isValidCnpj(
String cnpj) → bool - Validates the check digits of a 14-digit CNPJ.
-
isValidCpf(
String cpf) → bool - Validates the check digits of an 11-digit CPF.
-
maskCnpj(
String? cnpj) → String -
Masks a CNPJ for logging (
**.345.678/0001-**). -
maskCpf(
String? cpf) → String -
Masks a CPF for logging, keeping only the middle digits
(
***.456.789-**), as expected by the Brazilian data protection law.
Constants
- oidCnpj → const String
-
otherNamecarrying the CNPJ of a legal entity. - oidCompanyName → const String
-
otherNamewith the business name of a legal entity. - oidDnSerialNumber → const String
-
serialNumberattribute of the Subject DN. For a natural person it holds the CPF; for a legal entity, the CNPJ. - oidLegalEntityCei → const String
-
otherNamewith the INSS-specific registration (CEI) of a legal entity. - oidLegalEntityResponsible → const String
-
otherNameof the person responsible for a legal entity: same positional layout as oidNaturalPerson. - oidLegalEntityResponsibleName → const String
-
otherNamewith the name of the person responsible for a legal entity. - oidNaturalPerson → const String
-
Natural-person
otherName: positional block with birth date, CPF, NIS and ID card. - oidNaturalPersonCei → const String
-
otherNamewith the INSS-specific registration (CEI) of a natural person — 12 digits. - oidVoterRegistration → const String
-
otherNamewith the voter registration (título de eleitor) of a natural person: 12 digits + 3 (zone) + 4 (section) + 22 (city/state).