【问题标题】:OpenSSL libs: 2 on Linux libcrypto and libssl and more than 13 on windows. What shall I link on windows to compile my sample?OpenSSL 库:Linux libcrypto 和 libssl 上 2 个,Windows 上超过 13 个。我应该在 Windows 上链接什么来编译我的示例?
【发布时间】:2011-07-21 20:03:39
【问题描述】:

所以我看this示例代码:

#include <stdio.h>
#include <string.h>
#include "openssl/sha.h"

void sha256(char *string, char outputBuffer[65])
{
    unsigned char hash[SHA256_DIGEST_LENGTH];
    SHA256_CTX sha256;
    SHA256_Init(&sha256);
    SHA256_Update(&sha256, string, strlen(string));
    SHA256_Final(hash, &sha256);
    int i = 0;
    for(i = 0; i < SHA256_DIGEST_LENGTH; i++)
    {
        sprintf(outputBuffer + (i * 2), "%02x", hash[i]);
    }
    outputBuffer[64] = 0;
}

int sha256_file(char *path, char outputBuffer[65])
{
    FILE *file = fopen(path, "rb");
    if(!file) return -534;

    byte hash[SHA256_DIGEST_LENGTH];
    SHA256_CTX sha256;
    SHA256_Init(&sha256);
    const int bufSize = 32768;
    byte *buffer = malloc(bufSize);
    int bytesRead = 0;
    if(!buffer) return ENOMEM;
    while((bytesRead = fread(buffer, 1, bufSize, file)))
    {
        SHA256_Update(&sha256, buffer, bytesRead);
    }
    SHA256_Final(hash, &sha256);

    sha256_hash_string(hash, outputBuffer);
    fclose(file);
    free(buffer);
    return 0;
}

int main()
{
    static unsigned char buffer[65];
    sha256("string", buffer);
    printf("%s\n", buffer);
}

我应该将哪些库链接到我的项目以在 Windows 上编译它?

【问题讨论】:

    标签: c windows visual-studio-2010 openssl sha256


    【解决方案1】:

    我使用 OpenSSL 的 pre-compiled DLL 风格,它对我来说很好用。

    【讨论】:

    • 我知道如何编译 tham 但是用 tham 来链接我的应用程序?
    • 您链接到属于 DLL 的导入 .lib 文件。或者,如果您没有将 OpenSSL 编译到 DLL 中,则转到静态 .lib 库。寻找libeay32.libssleay32.lib
    • 找不到sha256_hash_string
    猜你喜欢
    • 2011-09-27
    • 2021-03-28
    • 2010-11-12
    • 2017-04-01
    • 2021-01-21
    • 2011-03-20
    • 2017-02-21
    • 2011-03-15
    • 1970-01-01
    相关资源
    最近更新 更多