md5.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sun, 26 Jul 2009 18:14:15 +0200
changeset 102 b8ff193b1a01
parent 77 49e0babccb23
child 148 8a5cf98a00b6
permissions -rw-r--r--
Property java.library.path i've found out how to set the library path correctly with java tools committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * md5.c
 * Copyright (C) 2008 Markus Broeker
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/md5.h>

typedef unsigned char u_char;

int main (int argc, char **argv)
{
    char buffer[80];
    char text[80];

    unsigned char *md5_hash;
    char result[33];
    char byte[3];

    int i, j;

    if (argc != 2) {
        printf ("Usage: %s <text>\n", argv[0]);
        return EXIT_FAILURE;
    }

    /*
     * MD5 alters the input buffer
     */
    strcpy (buffer, argv[1]);
    strcpy (text, argv[1]);

    md5_hash = MD5 ((u_char *) buffer, strlen (buffer), NULL);

    for (i = 0, j = 0; i < 16; i++) {
        sprintf (byte, "%02x", (md5_hash[i] & 0xFF));
        result[j++] = byte[0];
        result[j++] = byte[1];
    }

    result[j] = 0;
    printf ("%s: %s\n", text, result);

    return EXIT_SUCCESS;
}