md5.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Tue, 19 May 2009 02:58:59 +0200
changeset 93 66b3596f71b6
parent 77 49e0babccb23
child 148 8a5cf98a00b6
permissions -rw-r--r--
make cross_getch invisible the cross_getch function will be called from the JNI Wrapper and must not be visible to others committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
     1
/**
77
49e0babccb23 HEADER TAGS
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 45
diff changeset
     2
 * md5.c
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
     4
 */
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
     5
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
     6
#include <stdio.h>
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
     7
#include <stdlib.h>
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
     8
#include <string.h>
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
     9
#include <openssl/md5.h>
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    10
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    11
typedef unsigned char u_char;
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    12
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    13
int main (int argc, char **argv)
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    14
{
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    15
    char buffer[80];
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    16
    char text[80];
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    17
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    18
    unsigned char *md5_hash;
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    19
    char result[33];
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    20
    char byte[3];
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    21
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    22
    int i, j;
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    23
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    24
    if (argc != 2) {
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    25
        printf ("Usage: %s <text>\n", argv[0]);
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    26
        return EXIT_FAILURE;
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    27
    }
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    28
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    29
    /*
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    30
     * MD5 alters the input buffer
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    31
     */
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    32
    strcpy (buffer, argv[1]);
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    33
    strcpy (text, argv[1]);
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    34
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    35
    md5_hash = MD5 ((u_char *) buffer, strlen (buffer), NULL);
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    36
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    37
    for (i = 0, j = 0; i < 16; i++) {
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    38
        sprintf (byte, "%02x", (md5_hash[i] & 0xFF));
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    39
        result[j++] = byte[0];
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    40
        result[j++] = byte[1];
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    41
    }
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    42
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    43
    result[j] = 0;
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    44
    printf ("%s: %s\n", text, result);
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    46
    return EXIT_SUCCESS;
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
diff changeset
    47
}