Private/public key Authentication failed (wodSSH / wodSSH.NET)

by sji, (3 hours, 56 minutes ago)

I'm struggling to authenticate with an OpenSSH Server (Windows server 2022) using public key authentication.
I used "ssh-keygen -t rsa" command to create private/public key and put the public key into the Server ~/.ssh/id_rsa.pub and can connect to the Server via "ssh login@xx.x.xxx.x" DOS command,
But I received the error "0x800A7540" when using wodSSH lib publickey authauthenticate to connect to the Server (I have no problem when using password authentication via wodSSH to connect to the Server).
I also used ModKeys lib to generate private/public Keys "pKeys->Generate(ktype, var)".
if I used "pKeys->get_PublicKeySSH" to retrieve the public key, then I put it into Sever ~/.ssh2/authorized_keys.pub, and create ~/.ssh2/authorization which should have a line of text Key authorized_keys.pub in a separate line of the file
if I used pKeys->get_PublicKeyOpenSSH(ktype, &pubkey)" to get public key, then I put it into the Sever ~/.ssh/authorized_keys2

Code:
CoInitialize(NULL);
IwodSSHComPtr pSshCom;
HRESULT HR = NULL;
hr = pSshCom.CreateInstance(CLSID_wodSSHCom, NULL);
wSshEvents* pwEvents = new wSshEvents(pSshCom);
IKeysPtr pKeys;
CoInitialize(NULL);
hr = pKeys.CreateInstance(CLSID_Keys, NULL);
pSshCom->put_Blocking(VARIANT_TRUE);
pSshCom->PutPort(22);
pSshCom->put_Hostname(bstrSite);
pSshCom->put_Login(bstrUser);
//pSshCom->put_Password(bstrPswd);
pSshCom->PrivateKey = "C:\\Users\\builder\\.ssh\\id_rsa";
//hr = pKeys->Load("C:\\Users\\builder\\.sshReg\\id_rsa");
//pSshCom->PrivateKey = pKeys->GetPrivateKey(SSHKeyTypes::RSAkey);
pSshCom->Protocol = ProtocolsEnum::SSH2;
pSshCom->Authentication = AuthenticationsEnum::authPubkey;
try
{
hr = pSshCom->Connect();
}
catch (_com_error& e)
{
DWORD errorCode = GetLastError();
printf("Unable to connect: %s", e.ErrorMessage());
}
e= “0x800A7540”
or
const char* filename = "C:\\Users\\builder\\.ssh\\id_rsa";
std::ifstream file(filename, std::ios::binary | std::ios::ate);
std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg);
BYTE* buffer = new BYTE[size];
file.read(reinterpret_cast<char*>(buffer), size)
std::vector<BYTE> keyBytes(buffer, buffer + size);

SAFEARRAYBOUND bound;
bound.lLbound = 0;
bound.cElements = keyBytes.size();

SAFEARRAY* psa = SafeArrayCreate(VT_UI1, 1, &bound);
void* pData = nullptr;
SafeArrayAccessData(psa, &pData);
memcpy(pData, keyBytes.data(), keyBytes.size());
SafeArrayUnaccessData(psa);

VARIANT varKey;
VariantInit(&varKey);
varKey.vt = VT_ARRAY | VT_UI1;
varKey.parray = psa;
hr = pSshCom->put_PrivateKey(varKey);
pSshCom->put_Blocking(VARIANT_TRUE);
pSshCom->PutPort(22);
pSshCom->put_Hostname(bstrSite);
pSshCom->put_Login(bstrUser);
pSshCom->Protocol = ProtocolsEnum::SSH2;
pSshCom->Authentication = AuthenticationsEnum::authPubkey;
try
{
hr = pSshCom->Connect();
}
catch (_com_error& e)
{
DWORD errorCode = GetLastError();
printf("Unable to connect: %s", e.ErrorMessage());
}
e= “0x800A7540”