WodKeys GetPrivateKey returns an empty string (wodSSH / wodSSH.NET)
Hi Guys,
I am trying to enable a feature where a client can specify a private key file. Then using WodKeys, I call the load method and pass the file as a parameter. Next I use the PrivateKey property to retrieve the loaded RSA private key.
The load returns a hr of S_OK. But the private key property always returns an empty string.
Env: VS 6, C++, wodkeys ver: 1.2.3.12
A test private key looks like this:
-----BEGIN RSA PRIVATE KEY-----
MIICWQIBAAKBgQCd3pHjFzNV+vhQolKeWWpB71PYm50s7+xoPNKWcyHLetnzXa5j
eSCRyj4z2U0j8Fp0XGPnzoZUvRxRsWahmLZVVEBhm+fhnH+5ffiq8mK5uwYmLrwB
abENYyBm2BFLOCmtpxXDZ0n86nUs+aIpEvo18zgPhL/o+dCxvWSQ2og4qQIBIwKB
gBsQNkQv3OorBf8xxQUz5lRyK6F5wyxGYwqOFXjgiXNW44jOOyb+0mIiq5PcG9pG
degP1pzEUYrelyPyhp9cAf+62GGE3UJv+D+Yr0W3BC4JaIjP8onkAMFnLq0dmMLc
y4JQlSCVit3bIs/zU+yg3un/HjrQQhttOHbwqLNMkJiLAkEA0EyiSDuYTm+MgcIY
ylrxE/de6Fa/j0tOJgQ+oNu7TcPZOkuBNz+1ir9Jqq2x53EtGzU+ek4abRbB7uXA
ayOvOQJBAMIFhndMRcDoD1bi0NHEvBrXqTQJHX22rGM2i7U6dI0YBuwPBB0K4+Fq
0O41ktZ0s90nz0ua2TpF5Kf8D9tuZPECQE1eSuehG1BVUXIGQ7jf8ySsVnON72Eb
+HSFO9VY7cxtUK9AnbVvb1DKtPZAg+g/+s+Xbvo6RFRnidxj9wM5I9MCQEgQrkmR
W7yt9xGks/YkgGG90SH0wc+bnx2JSdWZXn2MlNtWCNeWVKQu/SVHGUhXO34HeOGR
SV7JgNCuFISz+ZsCQA6y+bIu/TmJk2t+gJ4hCKwQk1BB11TIPqb55Tl5qozbuHBK
xxxbv/dLZjQkvbPvwBfKt5R/efzuHUkjZaKsais=
-----END RSA PRIVATE KEY-----
Thanks
Arun
Re: WodKeys GetPrivateKey returns an empty string
Hi Arun,
Can you something like this in C++:
For generating keys:
http://www.weonlydo.com/index.asp?kb=1&View=entry&CategoryID=4&EntryID=54
For connecting to server with private key:
http://www.weonlydo.com/index.asp?kb=1&View=entry&CategoryID=4&EntryID=56
Let us know how it goes.
Regards,
Drazen
Re: WodKeys GetPrivateKey returns an empty string
Hi
In your sample you do the following [code]ssh1.PrivateKey = key
[/code]. But if you look at the COM IDL file in C++ it shows:
[code]virtual HRESULT __stdcall put_PrivateKey (
enum SSHKeyTypes KeyType,
BSTR pVal ) = 0;[/code]
I pass in the BSTR pointer. But it always returns an empty string.
Can you show a C++ example?
Thanks
Arun
Re: WodKeys GetPrivateKey returns an empty string
Hi Kreso,
Can you help me out with this problem. It is a bit urgent and I am kind of stuck at this juncture.
Thanks
Arun
Re: WodKeys GetPrivateKey returns an empty string
Arun,
why don't you use get_PrivateKeyData instead that use byte array?
http://www.weonlydo.com/Keys/Help/WODSSHKeyLib~Keys~PrivateKeyData.html
Kreso
Re: WodKeys GetPrivateKey returns an empty string
One more note - you probably use MFC which converts BSTR to CString for you. That's why you receive 0 string - because BSTR contains binary data and conversion done by MFC fails. You should convert it by yuorself using WideCharToMultiByte
Re: WodKeys GetPrivateKey returns an empty string
One more note - you probably use MFC which converts BSTR to CString for you. That's why you receive 0 string - because BSTR contains binary data and conversion done by MFC fails. You should convert it by yuorself using WideCharToMultiByte
Hi Kreso,
Thanks for your answer. Actually I am passing in a CComBStr.
[code]CComBSTR bsPrivateKey;
hr = m_pWodKeysCom->get_PrivateKey( ( SSHKeyTypes )type, &bsPrivateKey );[/code]
I do not convert it to a CString. I have tried setting the Private key property directly with a string before connecting and it works. Its the load and get_PrivateKey operation that is failing. We receive a file and hence the load operation makes it easier. If not, we have to read the file, store the contents in a byte array and then use it.
Any suggestion is welcome :)
Thanks
Arun
Re: WodKeys GetPrivateKey returns an empty string
And what about my PrivateKeyData post?
Re: WodKeys GetPrivateKey returns an empty string
And what about my PrivateKeyData post?
Hi Kreso... Thanks for the tip.. that worked. [:smile:]