使用 Google Cloud Platform MQTT 生成 JWT 密钥时出错



使用来自 Google Cloud Platform IOT Core 网站的这些说明 https://cloud.google.com/iot/docs/how-tos/credentials/jwts#iot-core-jwt-java 运行会生成此错误:

java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException:无效的密钥格式

使用的方法:

createJwtRsa(String projectId, String privateKeyFile)

"privateKeyFile"参数的编码是:到文件:rsa_private.pem,如下所示:

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

密钥是按照以下说明生成的:https://cloud.google.com/iot/docs/quickstart

任何帮助了解如何解决此错误将不胜感激。

我不得不在本页底部使用方法隐藏密钥: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

这解决了问题。

最新更新