new SshPrivateKey(byteData, passphrase) throws Invalid key format - no beginning

+1 vote
asked Jul 1 by djanjalia (170 points)

I am trying to get privateKey using:

SshPrivateKey privateKey = new SshPrivateKey(byteData, passphrase);

doing it with test data as:

var byteData = Encoding.UTF8.GetBytes(openSshPrivateKey);

openSshPrivateKey as "private_key" and password as "password" (just for testing)

it throws error: "Invalid key format - no beginning"

is there any validation for password or byte data?

1 Answer

+1 vote
answered Jul 1 by Lukas Matyska (60,690 points)
selected Jul 2 by djanjalia
Best answer

It seems that your openSshPrivateKey string is not in correct format. The value "private_key" will not work. The real private key data is expected.

Please visit the Private keys documentation, which also shows data format examples.

Also please check the SSH key generation section to learn how to generate your own SSH private key.