Hi, kann mir mal jemand erklären, wie man die md5.c benutzt?
Druckbare Version
Hi, kann mir mal jemand erklären, wie man die md5.c benutzt?
schau in die mddriver.c
k, danke. Trotzdem funktioniert das nicht ganz. in einer test.c gehts, aber in meiner ajccc.cpp gehts nicht. Code:
Fehler:Code:std::string getMD5(std::string pass)
{
MD5_CTX mdCntxt;
MD5Init(&mdCntxt);
const char* toDigest = pass.c_str();
char digest[32];
MD5Update(&mdCntxt, toDigest, sizeof(toDigest));
MD5Final(&mdCntxt);
int i;
for (i = 0; i < 16; i++)
sprintf(digest, "%s%02x", digest, mdCntxt.digest[i]);
return std::string(digest);
}
Code:giuly@Campi64 ~/ajccc/ajccc $ make
gcc -c -Wall -O3 md5.c -o md5.o
g++ -c -Wall -O3 tinyxml.cpp -o tinyxml.o
g++ -c -Wall -O3 tinyxmlparser.cpp -o tinyxmlparser.o
g++ -c -Wall -O3 tinyxmlerror.cpp -o tinyxmlerror.o
g++ -c -Wall -O3 tinystr.cpp -o tinystr.o
g++ -c -Wall -O3 ajccc.cpp -o ajccc.o
ajccc.cpp: In function `std::string getMD5(std::string)':
md5.h:51: error: too many arguments to function `void MD5Init()'
ajccc.cpp:13: error: at this point in file
md5.h:52: error: too many arguments to function `void MD5Update()'
ajccc.cpp:16: error: at this point in file
md5.h:53: error: too many arguments to function `void MD5Final()'
ajccc.cpp:17: error: at this point in file
make: *** [ajccc.o] Error 1
Nichts zu deinem eigentlichen Problem, aber trotzdem wichtig :)
Ist je nach Plattform entweder 4 oder 8, je nachdem wie lange ein Pointer ist.Code:sizeof(toDigest);
Ich gehe davon aus, daß die Funktion aber eher die Länge des Inputs wissen will, also vielleicht besser pass.size() benutzen.
Ciao,
_
:)Code:std::string getMD5(std::string pass)
{
MD5_CTX mdCntxt;
MD5Init(&mdCntxt);
char digest[32];
MD5Update(&mdCntxt, pass.c_str(), pass.size());
MD5Final(&mdCntxt);
for (int i = 0; i < 16; i++)
sprintf(digest, "%s%02x", digest, mdCntxt.digest[i]);
return std::string(digest);
}
--
das wird wohl irgendein Problem mit dem Header sein, weil da einfach
steht, und das versteht g++ wohl nicht.Code:void MD5Final ();
ich werd mal versuchen den Header zu korrigieren. :)
Edit: Das wars ;) Aber jetzt kommt was anderes :/
Hab den scheiß gecasted, aber beim linken wills nicht :/Code:giuly@Campi64 ~/ajccc/ajccc $ make
g++ -c -Wall -O3 ajccc.cpp -o ajccc.o
ajccc.cpp: In function `std::string getMD5(std::string)':
ajccc.cpp:15: error: invalid conversion from `const char*' to `unsigned char*'
ajccc.cpp:15: error: initializing argument 2 of `void MD5Update(MD5_CTX*, unsigned char*, unsigned int)'
make: *** [ajccc.o] Error 1
Sind die .os von gcc mit g++ inkompatibel oder was?Code:giuly@Campi64 ~/ajccc/ajccc $ g++ -o ajccc md5.o tinyxml.o tinyxmlparser.o tinyxmlerror.o tinystr.o ajccc.o
ajccc.o(.text+0x2ea): In function `getMD5(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
: undefined reference to `MD5Init(MD5_CTX*)'
ajccc.o(.text+0x2ff): In function `getMD5(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
: undefined reference to `MD5Update(MD5_CTX*, unsigned char*, unsigned int)'
ajccc.o(.text+0x309): In function `getMD5(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
: undefined reference to `MD5Final(MD5_CTX*)'
collect2: ld returned 1 exit status
giuly@Campi64 ~/ajccc/ajccc $ g++ -o ajccc tinyxml.o tinyxmlparser.o tinyxmlerror.o tinystr.o ajccc.o
ajccc.o(.text+0x2ea): In function `getMD5(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
: undefined reference to `MD5Init(MD5_CTX*)'
ajccc.o(.text+0x2ff): In function `getMD5(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
: undefined reference to `MD5Update(MD5_CTX*, unsigned char*, unsigned int)'
ajccc.o(.text+0x309): In function `getMD5(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
: undefined reference to `MD5Final(MD5_CTX*)'
collect2: ld returned 1 exit status
ist toll :)Code:external "C" { #include "md5.h" };