Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class KeyFiles
- Object
- KeyFiles
Reads keys out of PEM text, in the shapes key files come in, and hands back the one shape the runtime signs and verifies with: PKCS#8 DER for a private key, SubjectPublicKeyInfo DER for a public one.
byte[] signingKey = KeyFiles.readPrivateKey("/etc/orders/signing-key.pem");
byte[] publicKey = KeyFiles.publicKey(config.get("orders.public-key"));
| The file says | It is |
|---|---|
PRIVATE KEY | PKCS#8, RSA or EC: openssl genpkey |
RSA PRIVATE KEY | PKCS#1: openssl genrsa of old, ssh-keygen -m PEM |
EC PRIVATE KEY | SEC 1: openssl ecparam -genkey |
PUBLIC KEY | SubjectPublicKeyInfo: openssl pkey -pubout |
A key protected by a passphrase is refused, with a message that says how to
write it without one: a server that reads its key from a file has nobody to
ask for the passphrase, and one that reads the passphrase from the file next
to it has protected nothing. A certificate is refused too; extract its key
with openssl x509 -pubkey -noout.
Methods
public static byte[] privateKey(String pem)
throws IOException | The private key in pem, as PKCS#8 DER. |
public static byte[] publicKey(String pem)
throws IOException | The public key in pem, as SubjectPublicKeyInfo DER. |
public static byte[] readPrivateKey(String path)
throws IOException | The private key in the PEM file at path, as PKCS#8 DER. |
public static byte[] readPublicKey(String path)
throws IOException | The public key in the PEM file at path, as SubjectPublicKeyInfo DER. |
public static String read(String path)
throws IOException | The text of a key file. |
Inherited methods
Method details
privateKey
public static byte[] privateKey(String pem)
throws IOExceptionThe private key in
pem, as PKCS#8 DER.Throws
publicKey
public static byte[] publicKey(String pem)
throws IOExceptionThe public key in
pem, as SubjectPublicKeyInfo DER.Throws
readPrivateKey
public static byte[] readPrivateKey(String path)
throws IOExceptionThe private key in the PEM file at
path, as PKCS#8 DER.Throws
readPublicKey
public static byte[] readPublicKey(String path)
throws IOExceptionThe public key in the PEM file at
path, as SubjectPublicKeyInfo DER.Throws
read
public static String read(String path)
throws IOExceptionThe text of a key file. A
file: in front of the path is allowed, so a
setting copied from a Spring application reads the same file.