I\'m trying to load a private RSA key generated with ssl into java, my code is:
Generate the key:
openssl genrsa -out mykey.pem 1024
You get this error because you are reading a PKCS#8 key file, but your file has a PKCS#1 format (PKCS#1 has the BEGIN RSA PRIVATE KEY
header while PKCS#8 has the BEGIN PRIVATE KEY
header).
In order to read both PKCS#1 and PKCS#8 PEM files, I use the source code of Apache JMeter's org.apache.jmeter.protocol.oauth.sampler.PrivateKeyReader:
PrivateKey pk = (new PrivateKeyReader("/path/to/myfile.der")).getPrivateKey();