SshPrivateKey from Putty private key string

0 votes
asked Oct 17 by PJ (140 points)

Hi

We have Putty private and public key byte[] saved in db table. Using a very old version of rebex we were using private key byte[] to create SshPrivateKey object. Now trying to use latest rebex and byte[] is not working any more. Is there a way to use private key byte[] to create SshPrivateKey object in latest version?

Thanks

Applies to: Rebex SFTP

1 Answer

0 votes
answered Oct 17 by Lukas Pokorny (103,170 points)

Hi, we are not aware of any change to SshPrivateKey(byte[] data, string password = null) constructor that would prevent it from loading private keys that worked previously. Please let us know how the issue manifests itself and we will look into it. If it throws an exception, copy&paste the output of its ToString() method here.

commented Oct 17 by PJ (140 points)
Hi Lukas, thank you for replying. It throws exception, output of ToString() method is below.

System.Security.Cryptography.CryptographicException: Invalid key format.
at Rebex.Security.Cryptography.Pkcs.PrivateKeyInfo.lfxz(Byte[] ccz, Int32 cda, pvvf& cdb, KeyAlgorithm& cdc, String& cdd)
at Rebex.Security.Cryptography.Pkcs.PrivateKeyInfo.Load(Stream input, String password)
at Rebex.Net.SshPrivateKey.worq(Stream adu, String adv)
at Rebex.Net.SshPrivateKey..ctor(Byte[] data, String password)
commented Oct 17 by PJ (140 points)
FYI, I am using the trial version of File Transfer Pack. If I create SshPrivateKey using .ppk file then it works.
commented Oct 18 by PJ (140 points)
Hi Lucas, the issue has been resolved. The key string in the db table was only the private part of the .ppk file, not the entire ppk file content. I changed it and now it's working.
commented Oct 18 by Lukas Pokorny (103,170 points)
Hi, thanks for letting us know! I was just about to send you a hotfix that enhances the error message to make it possible to determine why exactly it failed - we'll include this enhancement in one of the next releases to make issues like this easier to resolve in future.
commented Oct 18 by PJ (140 points)
Thanks for the enhancement.
...