Class KeyFiles
java.lang.Object
com.codename1.backend.security.crypto.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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]privateKey(String pem) The private key inpem, as PKCS#8 DER.static byte[]The public key inpem, as SubjectPublicKeyInfo DER.static StringThe text of a key file.static byte[]readPrivateKey(String path) The private key in the PEM file atpath, as PKCS#8 DER.static byte[]readPublicKey(String path) The public key in the PEM file atpath, as SubjectPublicKeyInfo DER.
-
Method Details
-
privateKey
The private key inpem, as PKCS#8 DER.- Throws:
IOException
-
publicKey
The public key inpem, as SubjectPublicKeyInfo DER.- Throws:
IOException
-
readPrivateKey
The private key in the PEM file atpath, as PKCS#8 DER.- Throws:
IOException
-
readPublicKey
The public key in the PEM file atpath, as SubjectPublicKeyInfo DER.- Throws:
IOException
-
read
The text of a key file. Afile:in front of the path is allowed, so a setting copied from a Spring application reads the same file.- Throws:
IOException
-