Class Csr
- All Implemented Interfaces:
AutoCloseable
Create, load, inspect, and verify Certificate Signing Requests.
Chilkat.Csr is the Chilkat class for working with Certificate
Signing Requests. It can create CSRs from RSA or ECDSA private keys, set
common certificate subject fields, add custom subject fields by OID, include
Subject Alternative Names, request certificate extensions, export CSRs in
PEM or DER format, load existing CSRs, extract the public key, inspect SAN
values, and verify the CSR signature.
Create CSRs
Generate certificate signing requests using RSA or ECDSA private keys and the subject fields required by the certificate authority.
Subject fields
Set common X.509 subject fields such as common name, organization, organizational unit, locality, state, country, and email address.
Custom OID fields
Add custom subject attributes by object identifier when a certificate authority or application profile requires nonstandard fields.
Subject Alternative Names
Include DNS names, IP addresses, email addresses, URIs, or other SAN entries needed for modern TLS and identity certificates.
Extension requests
Request certificate extensions that the issuing CA may include in the final certificate.
Inspect and verify
Load an existing CSR, extract its public key, inspect requested names and fields, and verify that the CSR signature is valid.
Common pattern: Create or load a private key, populate the subject and SAN values required by the certificate authority, generate the CSR in PEM or DER format, submit it to the CA, and keep the private key secure because it will be needed when using the issued certificate.
For an extended overview, see Csr Class Overview.
</section>
Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when
done; an unclosed instance is freed when it becomes unreachable.
- See Also:
- Online reference
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds one Subject Alternative Name to the CSR that will be generated.voidgenCsrBd(PrivateKey privKey, BinData csrData)Generates a PKCS #10 Certificate Signing Request using the supplied RSA or elliptic-curve private key and writes the binary DER representation tocsrData.genCsrPem(PrivateKey privKey)Generates a PKCS #10 Certificate Signing Request using the suppliedPrivateKeyand the subject fields, Subject Alternative Names, extension request, and signature settings currently configured on this object.Gets or sets the subject common name (CN), OID2.5.4.3, for the CSR.Gets or sets the subject organization name (O), OID2.5.4.10.Gets or sets the subject organizational unit name (OU), OID2.5.4.11.Gets or sets the subject country name (C), OID2.5.4.6.Gets or sets the legacy PKCS #9emailAddresssubject attribute, OID1.2.840.113549.1.9.1.voidgetExtensionRequest(Xml extensionReqXml)Retrieves the PKCS #9extensionRequestattribute, OID1.2.840.113549.1.9.14, from the currently loaded CSR.Gets or sets the message-digest algorithm used when signing a generated CSR.Gets or sets the subject locality name (L), OID2.5.4.7.Gets or sets the hash algorithm used by MGF1 in an RSASSA-PSS CSR signature.booleanControls the RSA signature scheme used when generating a CSR with an RSA private key.voidgetPublicKey(PublicKey pubkey)Copies the public key contained in the currently loaded CSR intopubkey.voidgetSans(StringTable sans)Retrieves the Subject Alternative Names requested by the currently loaded CSR and writes them to the suppliedStringTable.getState()Gets or sets the subject state or province name (ST, sometimes displayed asS), OID2.5.4.8.getSubjectField(String oid)Returns the value of a subject distinguished-name attribute from the currently loaded or configured CSR, identified by its object identifier.voidloadCsrPem(String csrPemStr)Loads a PEM-encoded PKCS #10 Certificate Signing Request.voidsetCommonName(String value)Sets theCommonNameproperty; seegetCommonName().voidsetCompany(String value)Sets theCompanyproperty; seegetCompany().voidsetCompanyDivision(String value)Sets theCompanyDivisionproperty; seegetCompanyDivision().voidsetCountry(String value)Sets theCountryproperty; seegetCountry().voidsetEmailAddress(String value)Sets theEmailAddressproperty; seegetEmailAddress().voidsetExtensionRequest(Xml extensionReqXml)Sets the PKCS #9extensionRequestattribute, OID1.2.840.113549.1.9.14, for the CSR to be generated.voidsetHashAlgorithm(String value)Sets theHashAlgorithmproperty; seegetHashAlgorithm().voidsetLocality(String value)Sets theLocalityproperty; seegetLocality().voidsetMgfHashAlg(String value)Sets theMgfHashAlgproperty; seegetMgfHashAlg().voidsetPssPadding(boolean value)Sets thePssPaddingproperty; seegetPssPadding().voidSets theStateproperty; seegetState().voidsetSubjectField(String oid, String value, String asnType)Sets a subject distinguished-name attribute identified byoid.voidVerifies the digital signature on the currently loaded CSR using the public key embedded in that request.Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
Csr
public Csr()Creates a newCsrobject.
-
-
Method Details
-
getCommonName
Gets or sets the subject common name (CN), OID2.5.4.3, for the CSR. For a TLS server request this has traditionally been a DNS hostname; for other certificate profiles it may identify a person, device, service, or organization.Chilkat requires this property when generating a CSR. The exact value and validation rules are determined by the certificate authority and certificate profile.
Do not use CN as a substitute for SAN: For modern TLS certificates, add every DNS hostname or IP address through
. Current TLS identity verification uses Subject Alternative Name entries, and the common name is retained primarily for compatibility and display.addSan(String, String)- Returns:
- the value of the
CommonNameproperty
-
setCommonName
Sets theCommonNameproperty; seegetCommonName().- Parameters:
value- the new value (notnull)
-
getCompany
Gets or sets the subject organization name (O), OID2.5.4.10. For organization-validated certificate profiles, this is typically the legal or verified organization name.This property is optional at the PKCS #10 level, but a certificate authority may require it or replace it with a value established during identity validation.
- Returns:
- the value of the
Companyproperty
-
setCompany
Sets theCompanyproperty; seegetCompany().- Parameters:
value- the new value (notnull)
-
getCompanyDivision
Gets or sets the subject organizational unit name (OU), OID2.5.4.11. It may identify a department, division, team, or other unit within the organization.This property is optional. Some public certificate profiles restrict or omit organizational-unit values, so follow the requirements of the receiving CA.
- Returns:
- the value of the
CompanyDivisionproperty
-
setCompanyDivision
Sets theCompanyDivisionproperty; seegetCompanyDivision().- Parameters:
value- the new value (notnull)
-
getCountry
Gets or sets the subject country name (C), OID2.5.4.6. The value is normally a two-letter uppercase ISO 3166-1 country code, such asUS,CA, orDE.This property is optional unless required by the certificate authority's enrollment profile.
X.520 encoding: The country-name attribute is defined as a two-character
PrintableString. Do not place a full country name such asUnited Statesin this field.- Returns:
- the value of the
Countryproperty
-
setCountry
Sets theCountryproperty; seegetCountry().- Parameters:
value- the new value (notnull)
-
getEmailAddress
Gets or sets the legacy PKCS #9emailAddresssubject attribute, OID1.2.840.113549.1.9.1. This property is optional.Prefer an email SAN for email identity: The subject-DN
emailAddressattribute is permitted for legacy compatibility but is deprecated in the Internet X.509 profile. When the certificate must identify an email address, also usewithaddSan(String, String)rfc822Name, as required by the target certificate profile.- Returns:
- the value of the
EmailAddressproperty
-
setEmailAddress
Sets theEmailAddressproperty; seegetEmailAddress().- Parameters:
value- the new value (notnull)
-
getHashAlgorithm
Gets or sets the message-digest algorithm used when signing a generated CSR. Supported values aresha1,sha256,sha384, andsha512. The default issha256.This property selects the digest for the CSR's proof-of-possession signature. It does not select the signature algorithm that the certificate authority will use on the issued certificate.
Avoid SHA-1 for new requests: Use
sha256or stronger unless a legacy enrollment system explicitly requires SHA-1. The digest must also be compatible with the supplied key type and the receiving CA.- Returns:
- the value of the
HashAlgorithmproperty
-
setHashAlgorithm
Sets theHashAlgorithmproperty; seegetHashAlgorithm().- Parameters:
value- the new value (notnull)
-
getLocality
Gets or sets the subject locality name (L), OID2.5.4.7. This usually identifies a city, town, or other local jurisdiction.This property is optional unless required by the certificate authority's enrollment profile.
- Returns:
- the value of the
Localityproperty
-
setLocality
Sets theLocalityproperty; seegetLocality().- Parameters:
value- the new value (notnull)
-
getMgfHashAlg
Gets or sets the hash algorithm used by MGF1 in an RSASSA-PSS CSR signature. This property applies only when the private key is RSA andisgetPssPadding()true.Supported values are
sha256,sha384, andsha512. The default issha256.Common choice: For straightforward interoperability, set this to the same digest selected by
unless the receiving profile explicitly specifies different RSASSA-PSS parameters.getHashAlgorithm()- Returns:
- the value of the
MgfHashAlgproperty
-
setMgfHashAlg
Sets theMgfHashAlgproperty; seegetMgfHashAlg().- Parameters:
value- the new value (notnull)
-
getPssPadding
public boolean getPssPadding()Controls the RSA signature scheme used when generating a CSR with an RSA private key. Whentrue, Chilkat signs using RSASSA-PSS. Whenfalse, the RSA signature uses the traditional RSASSA-PKCS1-v1_5 scheme. This property has no effect for elliptic-curve keys.Related settings:
selects the digest of the certification-request information. When PSS is enabled,getHashAlgorithm()selects the digest used by MGF1. Interoperability: RSASSA-PSS is a modern RSA signature scheme, but the receiving CA or enrollment protocol must support PSS algorithm parameters in PKCS #10 requests.getMgfHashAlg()- Returns:
- the value of the
PssPaddingproperty
-
setPssPadding
public void setPssPadding(boolean value)Sets thePssPaddingproperty; seegetPssPadding().- Parameters:
value- the new value
-
getState
Gets or sets the subject state or province name (ST, sometimes displayed asS), OID2.5.4.8.This property is optional unless required by the certificate authority. Use the full jurisdiction name expected by the CA, such as
Illinois, rather than assuming an abbreviation is accepted.- Returns:
- the value of the
Stateproperty
-
setState
Sets theStateproperty; seegetState().- Parameters:
value- the new value (notnull)
-
addSan
Adds one Subject Alternative Name to the CSR that will be generated. Call this method once for each name to request. The SAN values are carried as requested certificate extensions; the issuing certificate authority decides whether to validate and include them in the final certificate.sanTypeMeaning and examplednsNameA DNS hostname, such aswww.example.comor an allowed wildcard such as*.example.com.IPAddressAn IPv4 or IPv6 address, such as192.0.2.10or2001:db8::10.rfc822NameAn Internet email address, such asuser@example.com.uniformResourceIndicatorA URI. This is Chilkat's accepted keyword; the X.509GeneralNamefield is formally nameduniformResourceIdentifier.directoryNameAn X.500 distinguished name.registeredIDA registered object identifier.otherName,x400Address,ediPartyNameLess common X.509GeneralNameforms used by specialized profiles.TLS server certificates: Put every DNS name and IP address that clients must validate in the SAN extension. Modern TLS identity checking uses
dNSNameandiPAddressSAN entries rather than relying on the subject common name.- Parameters:
sanType- thesanTypeargument (notnull)sanValue- thesanValueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
genCsrBd
Generates a PKCS #10 Certificate Signing Request using the supplied RSA or elliptic-curve private key and writes the binary DER representation tocsrData.The generated request uses the subject fields, Subject Alternative Names, extension request, and signature settings currently configured on this object. The DER bytes are the same request data that would appear as the Base64 body returned by
.genCsrPem(PrivateKey)DER versus PEM: DER is the binary ASN.1 encoding of the CSR. PEM is that DER data encoded as Base64 with certificate-request header and footer lines. Use DER for binary protocols such as EST when required by the receiving system.
- Parameters:
privKey- theprivKeyargument (notnull)csrData- thecsrDataargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
genCsrPem
Generates a PKCS #10 Certificate Signing Request using the suppliedPrivateKeyand the subject fields, Subject Alternative Names, extension request, and signature settings currently configured on this object. The private key may be RSA or elliptic-curve (ECDSA).On success, returns the CSR in PEM form, normally enclosed by
-----BEGIN CERTIFICATE REQUEST-----and-----END CERTIFICATE REQUEST-----lines. The Base64 body is the DER-encoded PKCS #10 request.What a CSR contains: A CSR contains the subject name, the public key derived from
privKey, optional attributes such as requested extensions, and a signature made with the corresponding private key. The private key itself is never included. Signature settings:selects the digest. For RSA keys,getHashAlgorithm()andgetPssPadding()control whether RSASSA-PSS is used and which MGF1 digest is encoded in its parameters.getMgfHashAlg()- Parameters:
privKey- theprivKeyargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getExtensionRequest
Retrieves the PKCS #9extensionRequestattribute, OID1.2.840.113549.1.9.14, from the currently loaded CSR. When present, the requested extensions are loaded intoextensionReqXmlas Chilkat ASN.1 XML.CSR contents only: The returned XML describes extensions requested by the applicant. It does not show which extensions a certificate authority ultimately accepted or placed in an issued certificate.
- Parameters:
extensionReqXml- theextensionReqXmlargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getPublicKey
Copies the public key contained in the currently loaded CSR intopubkey. The resultingPublicKeyobject is independent of the CSR and contains no private-key material.Proof of possession: A PKCS #10 request is signed with the private key corresponding to this public key. Use
to check that relationship; merely extracting the public key does not verify the CSR signature.verifyCsr()- Parameters:
pubkey- thepubkeyargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getSans
Retrieves the Subject Alternative Names requested by the currently loaded CSR and writes them to the suppliedStringTable.Requested, not issued: These values are taken from the CSR's extension-request data. They describe what the applicant asked the CA to place in the certificate, not what a CA has validated or will necessarily issue.
- Parameters:
sans- thesansargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getSubjectField
Returns the value of a subject distinguished-name attribute from the currently loaded or configured CSR, identified by its object identifier. For example, OID2.5.4.9identifies streetAddress.OID-based lookup: The short names commonly displayed in certificate tools, such as
CN,O,OU, andC, are labels for specific OIDs. This method uses the numeric OID so uncommon or application-specific attributes can also be retrieved.- Parameters:
oid- theoidargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadCsrPem
Loads a PEM-encoded PKCS #10 Certificate Signing Request. On success, the subject properties and retrieval methods on this object reflect the values contained in the loaded request, including its public key, Subject Alternative Names, and extension-request attribute when present.Loading is not verification: Parsing a CSR does not prove that its signature is valid. Call
to verify that the request was signed by the private key corresponding to the public key carried in the CSR. No private key is loaded: A PKCS #10 request contains only the public key and signature. The applicant must retain the original private key separately for use with the certificate issued by the CA.verifyCsr()- Parameters:
csrPemStr- thecsrPemStrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setExtensionRequest
Sets the PKCS #9extensionRequestattribute, OID1.2.840.113549.1.9.14, for the CSR to be generated.extensionReqXmlsupplies the requested X.509 extensions as ASN.1 represented in Chilkat XML form.Purpose of extensionRequest: PKCS #10 has no certificate-extension field of its own. Requested X.509 extensions, such as Subject Alternative Name, key usage, or extended key usage, are commonly carried in this signed attribute. A request is not a command: The certificate authority may ignore, modify, reject, or independently validate any requested extension according to its enrollment profile and security policy.
- Parameters:
extensionReqXml- theextensionReqXmlargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setSubjectField
Sets a subject distinguished-name attribute identified byoid. For example, OID2.5.4.9identifies streetAddress. Use the dedicated properties such as,getCommonName(), andgetCompany()for the commonly used subject attributes.getCountry()asnTypespecifies the ASN.1 string type used to encode the value and may beUTF8String,IA5String, orPrintableString. UseUTF8Stringunless the attribute definition or certificate-authority profile requires another type.ASN.1 type Typical use
UTF8StringGeneral Unicode text and the preferred default for most modern directory attributes.IA5StringASCII-based attributes whose schema specifically requires IA5String, such as the legacy PKCS #9emailAddressattribute.PrintableStringAttributes constrained to the limited PrintableString character set, such as the X.520 country name.Schema matters: The OID determines the attribute's meaning and permitted syntax. A value can be valid text yet still be rejected by a CA if the selected ASN.1 type, length, or format does not match that attribute's schema or the CA's enrollment policy.
- Parameters:
oid- theoidargument (notnull)value- thevalueargument (notnull)asnType- theasnTypeargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
verifyCsr
public void verifyCsr()Verifies the digital signature on the currently loaded CSR using the public key embedded in that request. Returnstruewhen the signature is cryptographically valid; otherwise returnsfalse.What this proves: Successful verification shows that the request was signed using the private key corresponding to the included public key and that the signed request data has not been altered. What this does not prove: Signature verification does not validate the applicant's identity, confirm control of a DNS name or email address, approve requested extensions, establish trust, or issue a certificate. Those checks and policy decisions belong to the certificate authority.
- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-