Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class CertificationRequest
- Object
- 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.
Methods
public static CertificationRequest create(DistinguishedName subject, byte[] privateKey, List<String> dnsNames)
throws IOException | Creates and signs a request. |
public static CertificationRequest decode(byte[] der)
throws IOException | Reads a request from its DER. |
public static CertificationRequest fromPem(String pem)
throws IOException | The first CERTIFICATE REQUEST block of pem. |
public byte[] getEncoded() | The DER of this request. |
public String toPem() | The request as one PEM block. |
public DistinguishedName getSubject() | The subject the request asks for. |
public byte[] getPublicKey() | The public key, as SubjectPublicKeyInfo DER. |
public List<String> getDnsNames() | The DNS names of the subject alternative name extension request. |
public boolean verify()
throws IOException | Whether the request is signed by the key it carries, which proves the requester holds the private key. |
Inherited methods
Method details
create
public static CertificationRequest create(DistinguishedName subject, byte[] privateKey, List<String> dnsNames)
throws IOExceptionCreates and signs a request.
Parameters
subjectDistinguishedName- the subject; may be empty when
dnsNamessays who it is for privateKeybyte[]- the PKCS#8 key the certificate will be for, RSA, P-256 or
P-384. It must carry its public key, as every key
Cryptogenerates andopensslwrites does. dnsNamesList<String>- the DNS names to request; null or empty for none
Throws
decode
public static CertificationRequest decode(byte[] der)
throws IOExceptionReads a request from its DER.
Throws
fromPem
public static CertificationRequest fromPem(String pem)
throws IOExceptionThe first
CERTIFICATE REQUEST block of pem. NEW CERTIFICATE REQUEST,
which some older tools write, is read too.Throws
getEncoded
public byte[] getEncoded()The DER of this request.
toPem
public String toPem()The request as one PEM block.
getSubject
public DistinguishedName getSubject()The subject the request asks for.
getPublicKey
public byte[] getPublicKey()The public key, as SubjectPublicKeyInfo DER.
getDnsNames
public List<String> getDnsNames()The DNS names of the subject alternative name extension request.
verify
public boolean verify()
throws IOExceptionWhether 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