-
-
Notifications
You must be signed in to change notification settings - Fork 947
Invalid private key file for BouncyCastle generated EC private key file #1536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks, there is actually a very old PR for this: #179 I will get it merged when I next find time |
Thanks. For the moment I have a workaround - I just regex-replace the DEK-Info-Line and make the salt uppercase before I pass it to the PrivateKey constructor :-D
|
I merged that PR but I did note that a) BouncyCastle outputs the salt in uppercase these days (https://github.com/bcgit/bc-csharp/blob/63b2e6e5bd596acea200f70c0db8e376f958806b/crypto/src/openssl/MiscPemGenerator.cs#L252); and |
Thank you. I was (accidentally) using Portable.BouncyCastle 1.9.0, because another NuGet packaged depends on it. There are pretty many projects out there which still use Portable Bouncy Castle because it seems to work better with Unity. And 1.9.0 created the lowercase salt. I'm now rename the Portable.BouncyCastle package in my project, so I can use BouncyCastle.Cryptography 2.4.2 which in fact produces the salt in uppercase. |
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
The text was updated successfully, but these errors were encountered: