我正在尝试制作一个连接到ssh服务器(我的笔记本电脑)的c ++程序。服务器还可以,因为我可以通过putty连接。虽然到目前为止我写的程序不能。在我的代码中我使用库libssh.h并且用于开发我使用了visual studio 2015.我得到的错误是: crypt_set_algorithms2:没有找到3des-cbc的加密算法函数 到目前为止我还没找到任何东西,所以我希望得到你的帮助。 我使用的代码:
#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
ssh_session my_ssh_session;
int rc;
int port = 22;
int verbosity = SSH_LOG_PROTOCOL;
char *password;
// Open session and set options
my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1);
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "192.168.1.6");
ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, "john");
ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
ssh_options_set(my_ssh_session, SSH_OPTIONS_CIPHERS_C_S,"aes128-ctr");
//ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
// Connect to server
rc = ssh_connect(my_ssh_session);
if (rc != SSH_OK)
{
fprintf(stderr, "Error: %s\n", ssh_get_error(my_ssh_session)); //HERE IS WHERE I GET THE ERROR
ssh_free(my_ssh_session);
exit(-1);
}
// Verify the server's identity
// For the source code of verify_knowhost(), check previous example
/* if (verify_knownhost(my_ssh_session) < 0)
{
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
exit(-1);
}
*/
// Authenticate ourselves
password = "pass";
rc = ssh_userauth_password(my_ssh_session, NULL, password);
if (rc != SSH_AUTH_SUCCESS)
{
fprintf(stderr, "Error authenticating with password: %s\n",
ssh_get_error(my_ssh_session));
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
exit(-1);
}
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
}
答案 0 :(得分:3)
尝试使用不同的密码。 3des-cbc
已损坏,可能已在您的服务器上停用。
真有nice tutorial会话很简单。
删除该行使其在Ubuntu上为我工作(不知道你在哪里找到它):
ssh_options_set(my_ssh_session, SSH_OPTIONS_CIPHERS_C_S,"aes128-ctr");
如果没有,您使用的是什么版本的libssh
?它不是一个过时的吗?
答案 1 :(得分:0)
终于搞定了!我删除了
行ssh_options_set(my_ssh_session, SSH_OPTIONS_CIPHERS_C_S,"aes128-ctr");
然后我使用libssh v0-7.2 中的ssh.dll而不是之前使用的 v0-7.1 的ssh.dll。 ssh.dll位于 libssh-0.7.2 \ bin 中。如果您发现错误 msvcr120d.dll 错误,请尝试在visual studio中从调试更改为发布。