Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class Pem
- Object
- Pem
PEM, the base64 text form of DER that openssl reads and writes: one or
more blocks between -----BEGIN <label>----- and -----END <label>-----.
List<Pem.Block> blocks = Pem.decode(fullChainPem);
String pem = Pem.encode(Pem.CERTIFICATE, certificate.getEncoded());Text outside the blocks, such as the Bag Attributes lines openssl pkcs12 prints, is ignored. A block with RFC 1421 headers (an encrypted
traditional key) is refused, since its content is not plain DER.
Nested types
class Pem.Block | One PEM block: its label and its DER content. |
Fields
public static final String CERTIFICATE = "CERTIFICATE" | The label of an X.509 certificate. |
public static final String CERTIFICATE_REQUEST = "CERTIFICATE REQUEST" | The label of a PKCS#10 certification request. |
public static final String PRIVATE_KEY = "PRIVATE KEY" | The label of a PKCS#8 private key. |
public static final String PUBLIC_KEY = "PUBLIC KEY" | The label of a SubjectPublicKeyInfo. |
Methods
public static List<Pem.Block> decode(String pem)
throws IOException | Every block in pem, in order. |
public static List<byte[]> decode(String pem, String label)
throws IOException | The DER of every block labelled label, in order; empty when there is none. |
public static String encode(String label, byte[] der) | One block, with the base64 in 64 character lines as openssl writes it. |
Inherited methods
Field details
CERTIFICATE
public static final String CERTIFICATE = "CERTIFICATE"The label of an X.509 certificate.
CERTIFICATE_REQUEST
public static final String CERTIFICATE_REQUEST = "CERTIFICATE REQUEST"The label of a PKCS#10 certification request.
PRIVATE_KEY
public static final String PRIVATE_KEY = "PRIVATE KEY"The label of a PKCS#8 private key.
PUBLIC_KEY
public static final String PUBLIC_KEY = "PUBLIC KEY"The label of a SubjectPublicKeyInfo.
Method details
decode
public static List<Pem.Block> decode(String pem)
throws IOExceptionEvery block in
pem, in order.Throws
IOException- when there is no block, a block is not closed, or a block’s content is not base64
decode
public static List<byte[]> decode(String pem, String label)
throws IOExceptionThe DER of every block labelled
label, in order; empty when there is none.Throws
encode
public static String encode(String label, byte[] der)One block, with the base64 in 64 character lines as
openssl writes it.