Thread: Openssl Pipes with C Help?

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    5

    Openssl Pipes with C Help?

    Look my program read all lines from (plain.txt) and save temporary every read strings line by line into another text called(all.txt), i made the md5sum hash on each line separately of (all.txt) and saving this hashes on calculating.txt... then delete the all.txt and calculating.txt, creating a new copy of calculating (hashes.txt)

    I want to do this process one-way only with the command
    with array or something without using files.

    Code:
    echo -n (read string line) | openssl md5
    Code:
    plain.txt
    a
    b
    c
    d
    e
    f
    g
    Code:
    #include <unistd.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #define Plain "plain.txt" 
    
    int main(){
    
        FILE *fp;
        FILE *read_fp;
        FILE *read_tmp;
        int chars_read;
        char hash[1024] = "openssl dgst -md5 all.txt >> calculating.txt";
        char buffer[1024];
        char line[128];
    
        if ((fp = fopen(Plain, "r")) == NULL){
        perror (Plain);
        return (EXIT_FAILURE);
           }
    
        printf("\tCreating Hash Table. Please wait....\n" );
    
        while(!feof(fp))
        {
            fscanf(fp,"%s", &line);
    
            read_tmp = fopen("all.txt","w+");
            fprintf(read_tmp,"%s", &line);
            fclose(read_tmp); 
    
    
            read_fp = popen(hash,"r");
            if (read_fp != NULL) {
                while ((chars_read = fread(buffer, sizeof(char), 1024 , read_fp)) > 0 ){
                }
                pclose(read_fp);
            }
        }
    
        fclose(fp);
        system("sed '$d' calculating.txt > hashes.txt");
        system("rm all.txt");
        system("rm calculating.txt");
        printf("Hashes Calculated Successfully... [OK!]\n");
    
        return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You mean like this?
    Code:
    $ while read line ; do b=$(echo $line | openssl dgst -md5); echo "$line $b"; done < plain.txt 
    a 60b725f10c9c85c70d97880dfe8191b3
    b 3b5d5c3712955042212316173ccf37be
    c 2cd6ee2c70b0bde53fbe6cac3c8b8bb1
    d e29311f6f1bf1af907f9ef9f44b8328b
    e 9ffbf43126e33be52cd2bf7e01d627f9
    f 9a8ad92c50cae39aa2c5604fd0ab6d8c
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    5
    yes but the plaintext in one file and hashes in a second text! separately !

  4. #4
    Registered User
    Join Date
    Feb 2012
    Posts
    5
    nvm!delete this thread! i solve it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with OpenSSL
    By Ricardo_R5 in forum C Programming
    Replies: 0
    Last Post: 05-07-2007, 06:18 PM
  2. Using OpenSSL with Dev-C++
    By Smiley10 in forum C Programming
    Replies: 2
    Last Post: 07-08-2006, 10:27 AM
  3. openssl on win2k
    By rzcodeman in forum Networking/Device Communication
    Replies: 4
    Last Post: 04-09-2004, 07:58 PM
  4. OpenSSL and Win32 SSL API :: SSL/TLS
    By kuphryn in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-10-2004, 07:46 PM