How do I load my private key in a Java application?

The private key that you generate from the Layer Dashboard is PEM encoded. In order to read it in a Java application, you will need to convert it to PKCS8 format by issuing the following command in a terminal:

openssl pkcs8 -topk8 -nocrypt -outform DER -in layer.pem -out layer.pk8

You can then read it by doing the following:

DataInputStream dis = new DataInputStream(new FileInputStream(privKeyFile));
System.out.println((int) privKeyFile.length());
byte[] privateBytes = new byte[(int) privKeyFile.length()];
dis.readFully(privateBytes); dis.close();

You can see a more detailed example of this code here:
Have more questions? Submit a request