0
votes

Using these instructions from Google Cloud Platform IOT Core website https://cloud.google.com/iot/docs/how-tos/credentials/jwts#iot-core-jwt-java run generates this error:

java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: invalid key format

The method used:

createJwtRsa(String projectId, String privateKeyFile)

The "privateKeyFile" parm is coded: to the file: rsa_private.pem like:

private static final String PRIVATE_KEY_FILE_PATH = "/Volumes/Code/mqtt/nodejs-docs-samples/iot/mqtt_example/rsa_private.pem";

The key was generated following these instructions: https://cloud.google.com/iot/docs/quickstart

Any help to understand how to fix this error would be appreciated.

1
Using this library: io.jsonwebtoken.impl.crypto; - Craig D

1 Answers

1
votes

I had to covert the key using method at the bottom of this page: https://cloud.google.com/iot/docs/how-tos/credentials/keys

openssl pkcs8 -topk8 -inform PEM -outform DER -in rsa_private.pem \
-nocrypt > rsa_private_pkcs8

This fixed the issue.