Linux MD5 programming in C Language
2009-06-26 11:39
302 查看
在 Linux 调用 openssl 的 libcrypto.so* 库加密字符串
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/md5.h>
int main(int argc, char *argv[])
{
char password[68] = {0};
MD5_CTX x;
int i = 0, len;
char *out = NULL;
unsigned char d[16];
unsigned char tmp[128] = { 0 };
if (argc != 2) {
printf("Usage: %s <message>/n", argv[0]);
return -1;
}
strcpy(password, argv[1]);
MD5_Init(&x);
MD5_Update (&x, (char *) password, strlen(password));
MD5_Final(d, &x);
out = malloc(35);
memset(out, 0x00, 35);
strcpy(out, "$1$");
printf ("MD5(/"%s/") = ", password);
for (i = 0; i < 16; i++) {
sprintf (out + (i*2), "%02X", d[i]);
}
out[32] = 0;
printf ("%s/n", out);
return 0;
}
编译的时候记得调用 libcrypt.so :
gcc -Wall -o md5 md5.c -lcrypto
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/md5.h>
int main(int argc, char *argv[])
{
char password[68] = {0};
MD5_CTX x;
int i = 0, len;
char *out = NULL;
unsigned char d[16];
unsigned char tmp[128] = { 0 };
if (argc != 2) {
printf("Usage: %s <message>/n", argv[0]);
return -1;
}
strcpy(password, argv[1]);
MD5_Init(&x);
MD5_Update (&x, (char *) password, strlen(password));
MD5_Final(d, &x);
out = malloc(35);
memset(out, 0x00, 35);
strcpy(out, "$1$");
printf ("MD5(/"%s/") = ", password);
for (i = 0; i < 16; i++) {
sprintf (out + (i*2), "%02X", d[i]);
}
out[32] = 0;
printf ("%s/n", out);
return 0;
}
编译的时候记得调用 libcrypt.so :
gcc -Wall -o md5 md5.c -lcrypto
相关文章推荐
- Linux MD5 programming in C Language
- Guide to Assembly Language Programming in Linux
- linux arm programming in assembly language
- Macro expand in C programming language
- [go] How to call the class in other package in Go Programming Language
- [Java]the Keywords in Java Programming Language
- 《Shell Programming in Unix, Linux and OS X, 4th Edition 》 笔记之Can I Quote You On That?
- Linux Socket Programming In C++(3)
- An example in Linux programming <if--fi>
- Hello Gtk+ in Linux Assembly Language
- USB camera programming in linux
- C language——read ip address in linux
- Programming in the Ruby language
- Socket programming in C on Linux | tutorial
- Which of the following statement(s) equal(s) value 1 in C programming language?
- An Introduction to Bash Shell Programming in Linux
- C语言中指针, 数组和字符串(Pointer, Array and String in C Programming Language)
- Analysing the ASM code of a simple sample of C programming language at Linux Platform by GCC and GDB
- Using Assembly Language in Linux
- How to use C programing language in Linux as a expert[ZT]