MD5 encryption

This is a discussion on MD5 encryption within the C Programming forums, part of the General Programming Boards category; Hey all I am very new to c programming, instead I skipped to PHP programming. I am interested in writing ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    3

    MD5 encryption

    Hey all
    I am very new to c programming, instead I skipped to PHP programming. I am interested in writing a C programming, however I need to use an md5 encryption method. I know basic c programming, however ervything I have researched for this is too complex for me. If someone could please point me in the right direction, I would greatly appreciate it

    Thank you
    Chris

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >however ervything I have researched for this is too complex for me
    Maybe you're trying to do more than you're capable of at the moment. MD5 isn't exactly the kind of algorithm I would recommend to a beginner. Even if it were then I would recommend SHA-1 rather than MD5. Is this just a personal project, or are you required to implement MD5 in C for something?
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    3
    Hey
    I am making a user database system for a site my room mate and I are making, and I am looking into developing a litle program in c to add users and remove users to our leisure for testing purposes. I could easily write something in php to access from the internet to do this, however, that is a hassle. I would like to just open up my little c program to do this. My password encryption is a series of md5 and string reverse functions. If it will be too complicated, I will probably drop it and make a php utility.

    Chris

  4. #4
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    Why don't you use a free MD5 library instead of reinventing the wheel, or are you that curious on the innter workings of MD5?

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    3
    Well
    I would like to use a free library, however, the only ones I can find are usually to hard for me, a beginner, to work into my script.

  6. #6
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    Well, here's something I prepared earlier. The source of my program is here:
    Code:
    #include <stdio.h>
    #include <string.h>
    
    void hex_dump(unsigned char *, int);
    
    int main(void)
    {
        char thing_to_md5[] = "Hello, world!";
        unsigned char result[16];
        librad_md5_calc(result, thing_to_md5, strlen(thing_to_md5));
        printf("md5 of %s is ", thing_to_md5);
        hex_dump(result, 16);
        printf("\n");
        return 0;
    }
    
    void hex_dump(unsigned char *s, int sz)
    {
        int i;
        for (i = 0; i < sz; i++)
            printf("%02x", s[i]);
    }
    The key function is librad_md5_calc(unsigned char *output, unsigned char *input, unsigned int inputlen).

    output is a pointer to the buffer you want the result to go into, which will be 16 bytes. input is a pointer to the input buffer, and inputlen is the amount of bytes to read of the input buffer. This is because md5 works on arbitrary binary data, not just null terminated strings.

    To convert the result from a 16 byte unsigned char array to the canonical ascii representation of an md5sum, I have used a simple hex_dump function to illustrate.

    Of course, I have called one md5 implementation, which is too long to post here. I have attached md5.c and md5.h, the above program was appended to the bottom of md5.c, but for your own use, you should of course keep your normal code separate from md5.c

    My output:
    Code:
    md5 of Hello, world! is 6cd3556deb0da54bca060b4c39479839
    To confirm it's correct using the system md5sum utility:
    Code:
    echo -n 'Hello, world!' | md5sum
    6cd3556deb0da54bca060b4c39479839  -
    Attached Files Attached Files
    • File Type: c md5.c (11.0 KB, 644 views)
    • File Type: h md5.h (2.5 KB, 528 views)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 12:48 PM
  2. Some questions concerning smp and md5
    By keira in forum C Programming
    Replies: 6
    Last Post: 08-31-2007, 03:03 PM
  3. MD5 encryption.
    By Maz in forum C++ Programming
    Replies: 1
    Last Post: 11-21-2005, 01:46 AM
  4. File Encryption & Read/Write in Binary Mode
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 05:45 PM
  5. Implementing the MD5 encryption library in C
    By Weed4Me in forum C Programming
    Replies: 12
    Last Post: 11-09-2001, 02:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21