Class CertificationRequest
java.lang.Object
com.codename1.backend.security.pki.CertificationRequest
A PKCS#10 certification request: what a CA (an ACME server, a corporate CA,
openssl x509 -req) is sent to issue a certificate for a key.
byte[] key = Crypto.generateEcKey(Crypto.P256);
CertificationRequest csr = CertificationRequest.create(
DistinguishedName.parse("CN=api.example.com"), key,
Arrays.asList("api.example.com", "www.example.com"));
String pem = csr.toPem();
The request is signed with SHA-256 for an RSA key or a P-256 key, and with SHA-384 for a P-384 key. DNS names go in a subject alternative name extension request, which is where every CA reads them from.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CertificationRequestcreate(DistinguishedName subject, byte[] privateKey, List<String> dnsNames) Creates and signs a request.static CertificationRequestdecode(byte[] der) Reads a request from its DER.static CertificationRequestThe firstCERTIFICATE REQUESTblock ofpem.The DNS names of the subject alternative name extension request.byte[]The DER of this request.byte[]The public key, as SubjectPublicKeyInfo DER.The subject the request asks for.toPem()The request as one PEM block.booleanverify()Whether the request is signed by the key it carries, which proves the requester holds the private key.
-
Method Details
-
create
public static CertificationRequest create(DistinguishedName subject, byte[] privateKey, List<String> dnsNames) throws IOException Creates and signs a request.- Parameters:
subject- the subject; may be empty whendnsNamessays who it is forprivateKey- the PKCS#8 key the certificate will be for, RSA, P-256 or P-384. It must carry its public key, as every keyCryptogenerates andopensslwrites does.dnsNames- the DNS names to request; null or empty for none- Throws:
IOException
-
decode
Reads a request from its DER.- Throws:
IOException
-
fromPem
The firstCERTIFICATE REQUESTblock ofpem.NEW CERTIFICATE REQUEST, which some older tools write, is read too.- Throws:
IOException
-
getEncoded
public byte[] getEncoded()The DER of this request. -
toPem
The request as one PEM block. -
getSubject
The subject the request asks for. -
getPublicKey
public byte[] getPublicKey()The public key, as SubjectPublicKeyInfo DER. -
getDnsNames
-
verify
Whether the request is signed by the key it carries, which proves the requester holds the private key.- Throws:
IOException- when the signature algorithm is outside the profile
-