Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a straight forward implementation of the <code>md5sum</code> command that computes and displays the MD5 of the file specified on the command-line. It needs to be linked against the OpenSSL library (<code>gcc md5.c -o md5 -lssl</code>) to work. It's pure C, but you should be able to adapt it to your C++ application easily enough.</p> <pre><code>#include &lt;sys/types.h&gt; #include &lt;sys/stat.h&gt; #include &lt;sys/mman.h&gt; #include &lt;fcntl.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;openssl/md5.h&gt; unsigned char result[MD5_DIGEST_LENGTH]; // Print the MD5 sum as hex-digits. void print_md5_sum(unsigned char* md) { int i; for(i=0; i &lt;MD5_DIGEST_LENGTH; i++) { printf("%02x",md[i]); } } // Get the size of the file by its file descriptor unsigned long get_size_by_fd(int fd) { struct stat statbuf; if(fstat(fd, &amp;statbuf) &lt; 0) exit(-1); return statbuf.st_size; } int main(int argc, char *argv[]) { int file_descript; unsigned long file_size; char* file_buffer; if(argc != 2) { printf("Must specify the file\n"); exit(-1); } printf("using file:\t%s\n", argv[1]); file_descript = open(argv[1], O_RDONLY); if(file_descript &lt; 0) exit(-1); file_size = get_size_by_fd(file_descript); printf("file size:\t%lu\n", file_size); file_buffer = mmap(0, file_size, PROT_READ, MAP_SHARED, file_descript, 0); MD5((unsigned char*) file_buffer, file_size, result); munmap(file_buffer, file_size); print_md5_sum(result); printf(" %s\n", argv[1]); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload