MD5 is required in the project. Algorithm So I found several MD5 algorithm source code files on the Internet, and the result interfaces are different, which is a headache. Turning over the/usr/include directory in Linux, we found that md5.h is provided under/usr/include/OpenSSL/, So we wrote a small Code Tested:
# Include < Stdio. h >
# Include < OpenSSL / Md5.h >
# Include < Assert. h >
# Include < String . H >
Void Printhex ( Char * Buffer, Int Size, file * Fp = Stderr)
... {
Assert (null ! = Buffer );
Fprintf (FP, " ========================================================== ================== " );
Char * P = NULL;
Int I;
For (I = 0 , P = Buffer; I < Size; I ++ , P ++ )
... {
Fprintf (FP, " % 02x " , (Unsigned Char ) * P );
If (I % 16 = 15 )
... {
Fprintf (FP," ");
}
}
Fprintf (FP, " ========================================================== ================== " );
}
Void Test ()
... {
Char * Str = " It's a test " ;
Int Len = Strlen (STR );
Char Buf [ 16 ] = ... {0} ;
Char * P = ( Char * ) MD5 (unsigned Char * ) STR, Len, (unsigned Char * ) BUF );
Printhex (BUF, Sizeof (BUF ));
Printhex (p, 16 );
}
Int Main ()
... {
Test ();
Return 1;
}
/**/ /*
G ++-O testmd5.o-C testmd5.cpp-g-wall-werror
G ++-O testmd5 testmd5.o/usr/lib/libssl. So
*/
Note: Link/usr/lib/libssl. So when linking