invalid key format error on generating private key
See original GitHub issueIn which file did you encounter the issue?
java-docs-samples/iot/api-client/mqtt_example/src/main/java/com/google/cloud/iot/examples/MqttExample.java
Describe the issue
The command I used to generate rsa private key and certificate is this:
openssl req -x509 -newkey rsa:2048 -keyout rsa_private.pem -nodes -out rsa_cert.pem -subj "/CN=unused"
In createJwtRsa method, the private key file which is working for the Python MQTT sample, giving the following error:
java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: invalid key format
at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:217)
at java.security.KeyFactory.generatePrivate(KeyFactory.java:372)
Caused by: java.security.InvalidKeyException: invalid key format
at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:330)
at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:356)
at sun.security.rsa.RSAPrivateCrtKeyImpl.<init>(RSAPrivateCrtKeyImpl.java:91)
at sun.security.rsa.RSAPrivateCrtKeyImpl.newKey(RSAPrivateCrtKeyImpl.java:75)
at sun.security.rsa.RSAKeyFactory.generatePrivate(RSAKeyFactory.java:316)
at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:213)
... 3 more
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
invalid key format on generating RSA public key
1 Answer 1 ... You must have an error in the way you read the key back from the database. The following code...
Read more >What can I do if I'm getting an RSA Private Key is invalid error ...
If you are getting an RSA Private Key is invalid error when you try adding your .key file under Server > HTTPS &...
Read more >SSH Key Format Issues and Fixing the “invalid format” Error
In this tutorial, we talk about issues with the format of keys when establishing an SSH session. First, we generate a sample key...
Read more >Invalid Private key file error - Power Automate - Microsoft Learn
Load your existing private key file in PuTTY Key Generator. Select Conversions > Export OpenSSH key (not the force new file format option)....
Read more >"Invalid Private Key Pass Phrase and Private key combination ...
There could be multiple causes: 1) The wrong passphrase was used, double check. ... Then the key is in RFC-4716 format, and the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
When I use the following command to convert the pem into der format, it works. Is it the way it should work? As I have to use the same private key file on both the platforms, Java and Python.
openssl pkcs8 -topk8 -inform PEM -outform DER -in private_key_file -nocrypt > pkcs8_key
@parameshwargouda did you register the device’s public certificate that pairs with the private key (in PKCS8 format) used to connect?