Class Pkix
java.security types.
All operations are delegated to a single PkixProvider, resolved once as
follows: a ServiceLoader-published provider if present, else the class
named by the zeroecho.pkix.provider system property, else the built-in
BouncyCastle-backed provider. This keeps the concrete cryptographic toolkit an
implementation detail confined to the lib module.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]assembleCertificateOrCrl(byte[] tbs, byte[] signature, boolean crl) Reassembles a signed certificate or CRL from itstbsbytes and a raw signature, repeating the algorithm identifier embedded in thetbs.static byte[]assembleOcspResponse(byte[] tbsResponseData, byte[] signatureAlgorithmDer, byte[] signature) Reassembles a successfulOCSPResponsefrom itstbsResponseData, a DER-encoded signature algorithm identifier, and a raw signature.static byte[]assembleOcspResponse(byte[] tbsResponseData, byte[] signatureAlgorithmDer, byte[] signature, List<X509Certificate> chain) Reassembles a successful OCSP response from unsignedResponseData, an encoded signature algorithm, a raw signature and an ordered certificate chain.static PreCertificateResultbuildPreCertificate(byte[] tbsCertificateDer, List<byte[]> issuerChainDer, ContentSigner signer) Builds a CT pre-certificate by adding the CT poison extension to aTBSCertificateand signing it, ready for submission to CT logs.static byte[]buildServerKeygenCsr(byte[] originalCsrDer, PublicKey generatedPublicKey, PrivateKey generatedPrivateKey) Builds a new PKCS#10 CSR using a server-generated key pair, copying the subject DN and attributes from the original CSR, for use in EST/serverkeygen.static byte[]buildSubjectPublicKeyInfo(AlgorithmIdentifier algorithm, byte[] publicKeyBits) Builds the DER of aSubjectPublicKeyInfofrom an algorithm identifier and the raw public-keyBIT STRINGcontents.static CertificateBuilderCreates a certificate builder.static CertificationRequestBuilderCreates a certification-request builder.static CertIdcomputeCertId(X509Certificate issuer, BigInteger serialNumber, String digestAlgorithmOid) Computes an OCSPCertIdfor a certificate under a given issuer.static CrlBuilderCreates a CRL builder.static X500PrincipaldistinguishedName(List<RelativeDistinguishedName> relativeNames) Builds a byte-exact distinguished name from typed relative distinguished names.static StringdistinguishedNameString(List<RelativeDistinguishedName> relativeNames) Renders a distinguished name, built from typed relative distinguished names, as its canonical string form.static byte[]embedScts(byte[] tbsCertificateDer, List<SignedCertificateTimestamp> scts) Embeds a list of SCTs into aTBSCertificateas the SCT list extension (OID1.3.6.1.4.1.11129.2.4.2), replacing any existing CT poison or SCT list extension.static byte[]encodeAlgorithmIdentifier(AlgorithmIdentifier algorithm) Returns the DER encoding of an X.509AlgorithmIdentifier.static byte[]encodeCertsOnly(List<X509Certificate> chain) Encodes a list of X.509 certificates as a CMS certs-only message, suitable for EST/cacertsand/simpleenrollresponses.static byte[]encodeCsrAttrs(List<CsrAttribute> attributes) Encodes a list of CSR attributes as an RFC 7030CsrAttrsDER structure, suitable for EST/csrattrsresponses.static byte[]encryptPrivateKeyForRecipient(byte[] pkcs8PrivateKeyDer, X509Certificate recipientCertificate) Encrypts a PKCS#8 private key for a single recipient using CMSEnvelopedDatawith AES-256-GCM content encryption, for use in EST/serverkeygenresponses.static OcspResponseBuilderCreates an OCSP response builder.static AlgorithmIdentifierparseAlgorithmIdentifier(byte[] der) Parses a DER-encoded X.509AlgorithmIdentifier.static X509CertificateparseCertificate(byte[] der) Parses a DER-encoded X.509 certificate.static CertificationRequestparseCertificationRequest(byte[] der) Parses a DER-encoded PKCS#10 certification request.static X509CRLparseCrl(byte[] der) Parses a DER-encoded X.509 CRL.static CertificationRequestparseCsr(byte[] csrPemOrDer) Parses a PKCS#10 certification request from PEM or DER encoding, verifying the proof-of-possession self-signature before returning.static List<RelativeDistinguishedName> parseDistinguishedName(byte[] nameDer) Parses a DER-encoded X.500Nameinto its ordered, single-valued relative distinguished names, preserving each value's ASN.1 string type.static List<RelativeDistinguishedName> Parses a distinguished-name string into its ordered, single-valued relative distinguished names, preserving the written order.static List<CertificateExtension> parseExtensions(byte[] der) Parses a DER-encoded X.509Extensionssequence into typed extensions.static List<GeneralName> parseGeneralNames(byte[] der) Parses a DER-encodedGeneralNamessequence into typed general names.static OcspRequestparseOcspRequest(byte[] der) Parses a DER-encoded OCSP request.static OcspResponseparseOcspResponse(byte[] der) Parses a DER-encoded OCSP response.static SignedCertificateTimestampparseSct(byte[] jsonResponseBody) Parses a Signed Certificate Timestamp from the JSON response body returned by a CT log'sadd-pre-chainoradd-chainendpoint.static PkixProviderprovider()Returns the resolved PKIX provider.static PublicKeypublicKeyFromSubjectPublicKeyInfo(byte[] subjectPublicKeyInfoDer) Recovers a public key from a DER-encodedSubjectPublicKeyInfo.static ContentSignersigner(PrivateKey privateKey, AlgorithmIdentifier algorithm) Creates a content signer over a local private key.static byte[]subjectKeyIdentifier(PublicKey publicKey) Computes the standard subject key identifier for a public key.static AlgorithmIdentifiersubjectPublicKeyAlgorithm(byte[] subjectPublicKeyInfoDer) Extracts the algorithm identifier from a DER-encodedSubjectPublicKeyInfo.static byte[]subjectPublicKeyBytes(byte[] subjectPublicKeyInfoDer) Returns the raw contents of the public-keyBIT STRINGof a DER-encodedSubjectPublicKeyInfo.static byte[]subjectPublicKeyInfo(X509Certificate certificate) Returns the exact DER of theSubjectPublicKeyInfoembedded in a certificate.static ContentVerifierverifier(byte[] subjectPublicKeyInfoDer, AlgorithmIdentifier algorithm) Creates a content verifier over a DER-encodedSubjectPublicKeyInfoand a signature algorithm identifier, honouring any algorithm parameters carried by the identifier.static ContentVerifierverifier(PublicKey publicKey, AlgorithmIdentifier algorithm) Creates a content verifier over a public key.static booleanverifyAlternativeSignature(X509Certificate certificate, PublicKey issuerAlternativeKey) Verifies a certificate's standardized alternative signature against an explicitly trusted issuer alternative key.static booleanverifySct(SignedCertificateTimestamp sct, PublicKey ctLogPublicKey, byte[] preCertDer) Verifies an SCT's digital signature against a known CT log public key.
-
Method Details
-
provider
Returns the resolved PKIX provider.- Returns:
- the active provider
-
certificateBuilder
Creates a certificate builder.- Returns:
- a fresh certificate builder
-
verifyAlternativeSignature
public static boolean verifyAlternativeSignature(X509Certificate certificate, PublicKey issuerAlternativeKey) Verifies a certificate's standardized alternative signature against an explicitly trusted issuer alternative key. The subject alternative key extension does not establish issuer trust. No primary signature, validity interval or certification path is validated by this method.- Parameters:
certificate- nonnull certificate with all three alternative extensionsissuerAlternativeKey- nonnull expected issuer alternative public key- Returns:
- false for absent, malformed or invalid alternative signatures
- Throws:
NullPointerException- if an argument is nullUnsupportedOperationException- if the provider lacks this capability
-
parseCertificate
Parses a DER-encoded X.509 certificate.- Parameters:
der- the certificate DER- Returns:
- the parsed certificate
-
certificationRequestBuilder
Creates a certification-request builder.- Returns:
- a fresh CSR builder
-
parseCertificationRequest
Parses a DER-encoded PKCS#10 certification request.- Parameters:
der- the request DER- Returns:
- the parsed request
-
crlBuilder
-
parseCrl
Parses a DER-encoded X.509 CRL.- Parameters:
der- the CRL DER- Returns:
- the parsed CRL
-
ocspResponseBuilder
Creates an OCSP response builder.- Returns:
- a fresh OCSP response builder
-
parseOcspRequest
Parses a DER-encoded OCSP request.- Parameters:
der- the request DER- Returns:
- the parsed request
-
signer
Creates a content signer over a local private key.- Parameters:
privateKey- the signing private keyalgorithm- the signature algorithm identifier- Returns:
- a content signer
- Throws:
UnsupportedRoleException- if LMS/XMSS signing is requested; rejection precedes provider invocation
-
verifier
Creates a content verifier over a public key.- Parameters:
publicKey- the verifying public keyalgorithm- the signature algorithm identifier- Returns:
- a content verifier
-
verifier
public static ContentVerifier verifier(byte[] subjectPublicKeyInfoDer, AlgorithmIdentifier algorithm) Creates a content verifier over a DER-encodedSubjectPublicKeyInfoand a signature algorithm identifier, honouring any algorithm parameters carried by the identifier.- Parameters:
subjectPublicKeyInfoDer- the SPKI DER of the verifying keyalgorithm- the signature algorithm identifier- Returns:
- a content verifier
-
subjectKeyIdentifier
Computes the standard subject key identifier for a public key.- Parameters:
publicKey- the public key- Returns:
- the subject key identifier bytes
-
computeCertId
public static CertId computeCertId(X509Certificate issuer, BigInteger serialNumber, String digestAlgorithmOid) Computes an OCSPCertIdfor a certificate under a given issuer.- Parameters:
issuer- the issuer certificateserialNumber- the subject certificate serial numberdigestAlgorithmOid- the digest algorithm OID- Returns:
- the computed cert id
-
distinguishedName
Builds a byte-exact distinguished name from typed relative distinguished names.- Parameters:
relativeNames- the ordered relative distinguished names- Returns:
- the distinguished name
-
parseAlgorithmIdentifier
Parses a DER-encoded X.509AlgorithmIdentifier.- Parameters:
der- the algorithm-identifier DER- Returns:
- the parsed algorithm identifier
-
subjectPublicKeyAlgorithm
Extracts the algorithm identifier from a DER-encodedSubjectPublicKeyInfo.- Parameters:
subjectPublicKeyInfoDer- the SPKI DER- Returns:
- the subject public key algorithm identifier
-
publicKeyFromSubjectPublicKeyInfo
Recovers a public key from a DER-encodedSubjectPublicKeyInfo.- Parameters:
subjectPublicKeyInfoDer- the SPKI DER- Returns:
- the public key
-
parseOcspResponse
Parses a DER-encoded OCSP response.- Parameters:
der- the response DER- Returns:
- the parsed response
-
parseDistinguishedName
Parses a DER-encoded X.500Nameinto its ordered, single-valued relative distinguished names, preserving each value's ASN.1 string type.- Parameters:
nameDer- the DER of an X.500Name- Returns:
- the ordered relative distinguished names
-
parseDistinguishedNameString
Parses a distinguished-name string into its ordered, single-valued relative distinguished names, preserving the written order.- Parameters:
name- the distinguished-name string- Returns:
- the ordered relative distinguished names
-
subjectPublicKeyBytes
public static byte[] subjectPublicKeyBytes(byte[] subjectPublicKeyInfoDer) Returns the raw contents of the public-keyBIT STRINGof a DER-encodedSubjectPublicKeyInfo.- Parameters:
subjectPublicKeyInfoDer- the SPKI DER- Returns:
- the public-key bit-string content bytes
-
subjectPublicKeyInfo
Returns the exact DER of theSubjectPublicKeyInfoembedded in a certificate.- Parameters:
certificate- the certificate- Returns:
- the exact SPKI DER
-
buildSubjectPublicKeyInfo
Builds the DER of aSubjectPublicKeyInfofrom an algorithm identifier and the raw public-keyBIT STRINGcontents.- Parameters:
algorithm- the subject public-key algorithm identifierpublicKeyBits- the raw public-key bit-string content bytes- Returns:
- the SPKI DER
-
parseExtensions
Parses a DER-encoded X.509Extensionssequence into typed extensions.- Parameters:
der- the DER of anExtensionssequence- Returns:
- the parsed extensions in order
-
parseGeneralNames
Parses a DER-encodedGeneralNamessequence into typed general names.- Parameters:
der- the DER of aGeneralNamessequence- Returns:
- the parsed general names in order
-
assembleCertificateOrCrl
public static byte[] assembleCertificateOrCrl(byte[] tbs, byte[] signature, boolean crl) Reassembles a signed certificate or CRL from itstbsbytes and a raw signature, repeating the algorithm identifier embedded in thetbs.- Parameters:
tbs- thetbsCertificateortbsCertListDERsignature- the raw signature bytescrl-truefor a CRL,falsefor a certificate- Returns:
- the DER of the assembled signed object
-
assembleOcspResponse
public static byte[] assembleOcspResponse(byte[] tbsResponseData, byte[] signatureAlgorithmDer, byte[] signature) Reassembles a successfulOCSPResponsefrom itstbsResponseData, a DER-encoded signature algorithm identifier, and a raw signature.- Parameters:
tbsResponseData- thetbsResponseDataDERsignatureAlgorithmDer- the DER of the signatureAlgorithmIdentifiersignature- the raw signature bytes- Returns:
- the DER of the assembled OCSP response
-
assembleOcspResponse
public static byte[] assembleOcspResponse(byte[] tbsResponseData, byte[] signatureAlgorithmDer, byte[] signature, List<X509Certificate> chain) Reassembles a successful OCSP response from unsignedResponseData, an encoded signature algorithm, a raw signature and an ordered certificate chain. Certificates are embedded in the supplied order without sorting or trust validation. An empty chain omits the optionalcertsfield, matching the three-argument overload. No signer is invoked and the raw signature is not cryptographically verified by assembly.Inputs remain caller-owned and are not retained. The returned DER array is independent. Time and auxiliary memory are linear in response-data, algorithm, signature and total embedded-certificate bytes. No aggregate live-response size limit is introduced.
- Parameters:
tbsResponseData- nonnull DER-encoded unsignedResponseDatasignatureAlgorithmDer- nonnull DER-encoded signatureAlgorithmIdentifiersignature- nonnull raw signature byteschain- nonnull certificate list in exact embedding order, with no null elements- Returns:
- freshly encoded successful OCSP response DER
- Throws:
NullPointerException- if an argument or a chain element is nullIllegalArgumentException- if DER parsing or certificate encoding fails
-
encodeAlgorithmIdentifier
Returns the DER encoding of an X.509AlgorithmIdentifier.- Parameters:
algorithm- the algorithm identifier- Returns:
- the DER encoding
-
distinguishedNameString
Renders a distinguished name, built from typed relative distinguished names, as its canonical string form.- Parameters:
relativeNames- the ordered relative distinguished names- Returns:
- the string form of the distinguished name
-
parseCsr
public static CertificationRequest parseCsr(byte[] csrPemOrDer) throws CertificationRequestException Parses a PKCS#10 certification request from PEM or DER encoding, verifying the proof-of-possession self-signature before returning.PEM input is detected by the presence of a
-----BEGINheader; all other input is treated as DER. Base64-encoded DER without PEM headers is also accepted via standardBase64decoding.- Parameters:
csrPemOrDer- PEM or DER bytes of the certification request; must not be null- Returns:
- the parsed and verified certification request
- Throws:
CertificationRequestException- if the CSR cannot be parsed or its self-signature fails verification
-
encodeCertsOnly
Encodes a list of X.509 certificates as a CMS certs-only message, suitable for EST/cacertsand/simpleenrollresponses.- Parameters:
chain- ordered certificate list; must not be null or empty- Returns:
- DER-encoded CMS
ContentInfowrappingSignedData - Throws:
IllegalArgumentException- if encoding fails
-
encodeCsrAttrs
Encodes a list of CSR attributes as an RFC 7030CsrAttrsDER structure, suitable for EST/csrattrsresponses.- Parameters:
attributes- the CSR attributes to encode; must not be null- Returns:
- DER-encoded
CsrAttrssequence - Throws:
IllegalArgumentException- if encoding fails
-
buildServerKeygenCsr
public static byte[] buildServerKeygenCsr(byte[] originalCsrDer, PublicKey generatedPublicKey, PrivateKey generatedPrivateKey) Builds a new PKCS#10 CSR using a server-generated key pair, copying the subject DN and attributes from the original CSR, for use in EST/serverkeygen.- Parameters:
originalCsrDer- original PKCS#10 CSR DER (source of subject and attributes)generatedPublicKey- server-generated public keygeneratedPrivateKey- server-generated private key- Returns:
- new PKCS#10 CSR DER self-signed with the generated key
- Throws:
IllegalArgumentException- if CSR construction or signing failsUnsupportedRoleException- if the private key uses LMS/XMSS; rejection precedes provider invocation
-
encryptPrivateKeyForRecipient
public static byte[] encryptPrivateKeyForRecipient(byte[] pkcs8PrivateKeyDer, X509Certificate recipientCertificate) Encrypts a PKCS#8 private key for a single recipient using CMSEnvelopedDatawith AES-256-GCM content encryption, for use in EST/serverkeygenresponses.- Parameters:
pkcs8PrivateKeyDer- DER-encoded PKCS#8 private key to encryptrecipientCertificate- the recipient's certificate (public key used for wrap)- Returns:
- DER-encoded CMS
ContentInfowrapping theEnvelopedData - Throws:
IllegalArgumentException- if encryption fails
-
buildPreCertificate
public static PreCertificateResult buildPreCertificate(byte[] tbsCertificateDer, List<byte[]> issuerChainDer, ContentSigner signer) Builds a CT pre-certificate by adding the CT poison extension to aTBSCertificateand signing it, ready for submission to CT logs.- Parameters:
tbsCertificateDer- DER-encodedTBSCertificateissuerChainDer- DER-encoded issuer chain (issuer first, root last)signer- configured signer for the issuing CA key- Returns:
- pre-certificate DER and its chain
- Throws:
IllegalArgumentException- if pre-certificate construction or signing fails
-
embedScts
Embeds a list of SCTs into aTBSCertificateas the SCT list extension (OID1.3.6.1.4.1.11129.2.4.2), replacing any existing CT poison or SCT list extension.- Parameters:
tbsCertificateDer- DER-encodedTBSCertificatescts- verified SCTs to embed; must contain at least one entry- Returns:
- modified DER-encoded
TBSCertificatewith the SCT list extension - Throws:
IllegalArgumentException- if embedding fails
-
parseSct
Parses a Signed Certificate Timestamp from the JSON response body returned by a CT log'sadd-pre-chainoradd-chainendpoint.- Parameters:
jsonResponseBody- raw response body bytes from the CT log; must not benull- Returns:
- the parsed SCT
- Throws:
IllegalArgumentException- if the JSON is malformed or the SCT structure is invalid
-
verifySct
public static boolean verifySct(SignedCertificateTimestamp sct, PublicKey ctLogPublicKey, byte[] preCertDer) Verifies an SCT's digital signature against a known CT log public key.- Parameters:
sct- the SCT to verify; must not benullctLogPublicKey- EC or RSA public key of the CT log; must not benullpreCertDer- DER-encoded pre-certificate that was submitted; must not benull- Returns:
trueif the signature is valid,falseotherwise- Throws:
IllegalArgumentException- if the algorithm is unsupported or the key is invalid
-