BouncyCastle create PEM files for EC-keys with DEK-Info salt in lowercase, which prevents the PrivateKeyPattern to match the key.
This results in a SshException("Invalid private key file.") when trying to load the private key file.
https://github.com/sshnet/SSH.NET/blob/6b4524efbd84e3bf5f8f670a81cf1793484e9d24/src/Renci.SshNet/PrivateKeyFile.cs#L122C1-L123C1
Example:
-----BEGIN EC PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,d87771503957057a
This could be fixed by changing
DEK-Info: (?<cipherName>[A-Z0-9-]+),(?<salt>[A-F0-9]+)
to
DEK-Info: (?<cipherName>[A-Z0-9-]+),(?<salt>[a-fA-F0-9]+)
Fixed line would be
private const string PrivateKeyPattern = @"^-+ *BEGIN (?<keyName>\w+( \w+)*) *-+\r?\n((Proc-Type: 4,ENCRYPTED\r?\nDEK-Info: (?<cipherName>[A-Z0-9-]+),(?<salt>[a-zA-F0-9]+)\r?\n\r?\n)|(Comment: ""?[^\r\n]*""?\r?\n))?(?<data>([a-zA-Z0-9/+=]{1,80}\r?\n)+)(\r?\n)?-+ *END \k<keyName> *-+";
BouncyCastle create PEM files for EC-keys with DEK-Info salt in lowercase, which prevents the PrivateKeyPattern to match the key.
This results in a SshException("Invalid private key file.") when trying to load the private key file.
https://github.com/sshnet/SSH.NET/blob/6b4524efbd84e3bf5f8f670a81cf1793484e9d24/src/Renci.SshNet/PrivateKeyFile.cs#L122C1-L123C1
Example:
This could be fixed by changing
DEK-Info: (?<cipherName>[A-Z0-9-]+),(?<salt>[A-F0-9]+)to
DEK-Info: (?<cipherName>[A-Z0-9-]+),(?<salt>[a-fA-F0-9]+)Fixed line would be