jjzjj

c - OpenSSL 库 : 2 on Linux libcrypto and libssl and more than 13 on windows. 我应该在 Windows 上链接什么来编译我的示例?

coder 2024-06-19 原文

所以我看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 上编译它?

最佳答案

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

关于c - OpenSSL 库 : 2 on Linux libcrypto and libssl and more than 13 on windows. 我应该在 Windows 上链接什么来编译我的示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6782046/

有关c - OpenSSL 库 : 2 on Linux libcrypto and libssl and more than 13 on windows. 我应该在 Windows 上链接什么来编译我的示例?的更多相关文章

随机推荐