tar xjvf libmcrypt-2.5.8.tar.bz2
cd libmcrypt-2.5.8
./configure --prefix=/Volumes/2g/code/php_socket/libmcrypt
make
make install
vi mcrypt.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <mcrypt.h>
int main(int argc,char *argv[])
{
int i;
char *IV,*key;
int iv_size;
int key_size;
int bsize;
char *string="Wel123$ Linux Windows This is test";
MCRYPT td=mcrypt_module_open("des",NULL,"ecb",NULL);
if(td==MCRYPT_FAILED)
{
exit(0);
}
iv_size=mcrypt_enc_get_iv_size(td);
key_size=mcrypt_enc_get_key_size(td);
key=calloc(1,key_size);
memcpy(key,"pass",key_size);
IV=calloc(1,iv_size);
for(i=0;i<iv_size;i++)
{
IV[i]=0;
}
i=mcrypt_generic_init(td,key,key_size,IV);
bsize=mcrypt_enc_get_block_size(td);
char *b_buffer=calloc(1,bsize);
int delen=(strlen(string)+bsize-1)/bsize*bsize;
char *target=calloc(1,delen);
memcpy(target,string,strlen(string));
printf("\n%s\nlength=%d\n",target,delen);
mdecrypt_generic(td,target,delen);
printf("\nsource=%d\ndest=%d\n",(int)strlen(string),(int)strlen(target));
printf("\n");
for(i=0;i<strlen(target);i++)
{
printf("%2x",(char)*(target+i));
}
printf("\n");
mcrypt_generic_deinit(td);
mcrypt_module_close(td);
}
编译
gcc mcrypt.c -o mcrypt
-I/Volumes/2g/code/php_socket/libmcrypt/include -L/Volumes/2g/code/php_socket/libmcrypt/lib/ -lmcrypt