+1 vote
by (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
by (70.3k points)
selected by
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.