C SHA1()打开文件并在编译时出现哈希错误

C SHA1() open file and get hash error when compiling

我正在编写一个程序来获取一些文件的哈希值并对它们进行处理。我正在尝试提取哈希等,但在编译时出现错误。

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

int main ( int argc, char *argv[] ) {

    // para digitar em vez de   //char str[50] = {0};   //scanf("Enter file name:%s", str);     //scanf     if ( argc < 1 ) /* argc should be at least 2 for correct execution */
     {
        printf( "falta o ficheiro para ter hash: %s filename", argv[0] );
        }
        else
        {
        // filename to open
        FILE *file = fopen( argv[1], "r" );     //char str[] = "teste";     //const char str[] = "Original String";     unsigned char hash[SHA_DIGEST_LENGTH]; // == 20

    SHA1(FILE, sizeof(FILE), hash);

    printf("SHA1 of %s is %s\n", argv[1], hash);

        /* fopen returns 0, the NULL pointer, on failure */
        if ( file == 0 )
        {
            printf( "Could not open file\n" );
        }

    }
    return 0; }

编译时出现此错误:gcc sob.c -o sha -lcrypto

sob.c: In function ‘main’:
sob.c:24:7: error: expected expression before ‘FILE’
  SHA1(FILE, sizeof(FILE), hash);
       ^
sob.c:24:7: error: too few arguments to function ‘SHA1’
In file included from sob.c:2:0:
/usr/include/openssl/sha.h:126:16: note: declared here
 unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);
                ^

您不能将文件(或 FILE,这是一种类型,而不是变量)传递给 SHA1,而是需要将文件读入一个无符号字符数组并传递该数组!