 |
|
 |
I know this is old, but I just downloaded and used this code and ran into a bug. This class assumes that what you want to create a md5 digest from does not contain any null character. I was trying to checksum a file and had weird results, so I simply added a len parameter and removed the strlen in md5class.cpp.
Cheers.
|
|
|
|
 |
|
 |
I transfer a Password(exp:'ABCD') to MD5(exp:I Got 'cb08ca4a........').
But i want the MD5('cb08ca4a........') restore to password('ABCD')..
How can i do?
ewtqrqewfgaewtqqrw
|
|
|
|
 |
|
 |
What you want to do is defeat MD5. The whole purpose of the MD5 alogorithm is to make it close to impossible to go from the hash back to the plain text. This kind of hash is the basis of asymetrical cryptography.
It is in practice impossible to go from the hash back to the plain text.
If you need to go plain text -> cyphertext -> plain text then you need to use a so called 'symetrical' algorithm.
-- modified at 14:44 Friday 24th March, 2006
|
|
|
|
 |
|
 |
Hi.
This tip is for those who still have problem with reusing this CMD5 code to MFC/eVC++ project even though tried correcting source/setting several times after having taken advices from this board.
I know some people here have already put some comments on this issue - Thank you -, however, I found this quite confusing.
It took me 30 minutes of correcting the code/setting as you told here to finally succeed compiling: This is why I'm putting new one here now.
Let's get to the point.
1. Copy and paste the files you need to reuse from CMD5 project
2. Add them to your project, compile and check the error messages
3. You will see your compiler says "blah~blah~ Unexpected end of file Blah~"
4. Don't put #include "stdafx.h" to md5c.c!! (Some person here told so... but don't do that!!)
5. Instread, put #include "stdafx.h" to md5class.cpp
5. Just go to project-setting and select C++ tab
6. select "precompiled headers" category and change it to Automatic use of precompiled headers
7. put stdafx.h on the editbox next to "Through Header"
8. rebuild all
This is how it worked out for me at least.
Thanks.
|
|
|
|
 |
|
 |
Hi,
It's been now many hours that I try to compile these files on Visual C++ 2005 Express, but no way!
The project compiles well on Visual Studio 2005, though. I don't know why, I get the following error messages:
1>Compiling...
1>md5class.cpp
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\...\md5class.cpp(93) : error C2065: 'MD5_CTX' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\...\md5class.cpp(93) : error C2146: syntax error : missing ';' before identifier 'context'
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\...\md5class.cpp(93) : error C2065: 'context' : undeclared identifier
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\...\md5class.cpp(94) : error C3861: 'MD5Init': identifier not found
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\...\md5class.cpp(97) : error C3861: 'MD5Update': identifier not found
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\...\md5class.cpp(98) : error C3861: 'MD5Final': identifier not found
1>Build log was saved at "file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\...\Debug\BuildLog.htm"
1>listing_api_calls - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The MD5_CTX struct is defined in MD5.h and implemented in md5class.cpp
Do you have an idee?
thanks in advance,
Flo
|
|
|
|
 |
|
 |
Ok,
It was because I didn't placed the #include "stdafx.h" at the first line but after some #define blah_blah
Then the above error messages vanished.
regards,
Flo
|
|
|
|
 |
|
 |
thanks to Jae Hyoung Kim.
smaller tip
step following is not essential
5. Instread, put #include "stdafx.h" to md5class.cpp
|
|
|
|
 |
|
 |
As of August 2004:
MD5 = dead, SHA-1 on life support[^]
The security industry recommends all new applications use _AT LEAST_ SHA-256 if not SHA-384 or SHA-512.
MD5 is still considered "okay" for anything not security related.
|
|
|
|
 |
|
 |
Hi,
Does thic class support Unicode? I think it does not. Can anyone give me the unicode version?
Thanks.
|
|
|
|
 |
|
 |
yes, the posted control does not support unicode. i made the following change to get it to run on a pocketpc. basically, he home-brewed memset and memcpy and they do not support unicode strings.
in md5c.cpp, MD5Update function, i replaced:
//MD5_memcpy(((POINTER)&context->buffer[index], (POINTER)input, partLen);
memcpy(&context->buffer[index], input, partLen * sizeof(TCHAR));
-and-
/* Buffer remaining input */
//MD5_memcpy((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen-i);
memcpy(&context->buffer[index], &input[i], (inputLen - i) * sizeof(TCHAR));
it seems to work well now.
hth
jeff zamora
|
|
|
|
 |
|
 |
ye, and i have now found i must simply chanage the function parameter @data from TEXT to NTEXT
|
|
|
|
 |
|
 |
Hai
How to get a user id from network in C++ program
can anyone give me the sample code
Siva
|
|
|
|
 |
|
|
 |
|
 |
Rename md5.c to md5.cpp and try again, seems it works in comand line mode it shows array sequense like this
->%@#$@%$#@%$#@
a->^&%&^%*&^%*(&%&%
e.t.c.
|
|
|
|
 |
 | Bug!  |  | The Coder | 11:22 2 Mar '03 |
|
 |
As pointed out by csteow this class (silently!) produces wrong results for binary data (exes, pictures, ...). It uses ::strlen(m_plainText) in CMD5::calcDigest(). strlen stops at the first '\0' and ignores the rest.
|
|
|
|
 |
|
 |
Here are the relevent definations from the headerfile:
CMD5(const char* plainText); //set plaintext in ctor
void setPlainText(const char* plainText);
I need to clarify these to state that "plaintext" refers to null terminated strings, since you can have text that isn't null terminated.
But I think it's a bit of a stretch to feed "exes, pictures...." to something called "plaintext" and then be surprised when the function doesn't do what you expect.
thanks,
Jim
|
|
|
|
 |
|
 |
Hello there,
thanx a lot for this good class. But in my opinion it isn't secure enough.
Thats the reason why i changed some Methods in your Class.
First of all we have to give the programmer the possibility to set up an Secret Key.
So you have to change the following things.
The First Function is SetPlainText !
void CMD5::setPlainText(const char* plainText,const char* SecretKey)
{
//set plaintext with a mutator, it's ok to
//to call this multiple times. If casting away the const-ness of plainText
//worries you, you could either make a local copy of the plain
//text string instead of just pointing at the user's string, or
//modify the RFC 1321 code to take 'const' plaintext, see example below.
m_plainText = const_cast(plainText);
m_secretkey = const_cast(SecretKey); // Added by Karsten Noa (Germany)
m_digestValid = calcDigest();
}
The Second Function is the Constructor.
CMD5::CMD5(const char* plainText,const char* SecretKey)
{
m_plainText = const_cast(plainText); //get a pointer to the plain text. If casting away the const-ness worries you,
//you could make a local copy of the plain text string.
m_secretkey = const_cast(SecretKey);
m_digestString[32]=0;
m_digestValid = calcDigest();
}
And last but not least we have to change the coding method in ->
bool CMD5::calcDigest()
{
//See RFC 1321 for details on how MD5Init, MD5Update, and MD5Final
//calculate a digest for the plain text
MD5_CTX context;
MD5Init(&context);
//the alternative to these ugly casts is to go into the RFC code and change the declarations
MD5Update(&context, reinterpret_cast(m_secretkey), ::strlen(m_secretkey)); // This Line where added by Karsten Noa (Germany)
MD5Update(&context, reinterpret_cast(m_plainText), ::strlen(m_plainText));
MD5Final(reinterpret_cast (m_digest),&context);
//make a string version of the numeric digest value
int p=0;
for (int i = 0; i<16; i++)
{
::sprintf(&m_digestString[p],"%02x", m_digest[i]);
p+=2;
}
return true;
}
so for the first time thats all folks !
|
|
|
|
 |
|
 |
You wrote: "minor changes", but will the output still be compatible with standard md5? If not, I think you should have a salted (standard?) hashing method, and a standard MD5 compatible one. IE:
MD5::HashUnSalted(buf).
|
|
|
|
 |
|
 |
The class does not salt the input text. I will pass the compatablity test included in the RFC. Salting is just a technique the user can use if it is appropriate to the specific application.
Jim
|
|
|
|
 |
|
 |
First of all, i think this is a great article. I rate it 5.
I don't understand why recently on CodeProject we have such many not constructive comments.
This article not about how to use strong criptography, but for those who wants just use MD5 with greath C++ class.
So before you want to start thread about "hackers", i think u can create by self a new article and give it a title "How to hack hackers".
Implement a some new feature or fix a bug - and g0 - you can criticize anything, but before this you can only look what great things other coders do.
Best regards.
|
|
|
|
 |
|
 |
This is indeed a great & simple class. It took me some hours of search and reading compiler errors until I found this one which works just great without weird dependencies.
|
|
|
|
 |
|
 |
I used your class and I got it to output md5's once, but now it outputs this all the time :
ÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝp
WTF ! I didnt make any changes to your class, but I did put the code into a DLL.
It should still work when called from my app though. THe above output seems like a buffer isnt NULL terminated or something. Any thoughts as to why this is being outputted ?
|
|
|
|
 |
|
 |
Try making the buffer in your dll static. The ÝÝ... stuff means that the pointer is pointing to memory that has not been allocated, so there is a memory allocation issue somewhere.
Jim
|
|
|
|
 |
|
 |
You can't get from MD5 to the password but the password itself is still relatively simple. Hackers can go from "A" to "zzzzzzzz" and check the MD5 of each string against the stored value (oldest trick in the book).
So in addition to MD5 you should do something strange like running MD5 twice and then flip it and then combine with SHA1. If the hacker doesn't know your method then he can't use brute force.
|
|
|
|
 |
|
 |
That's called "salting" the hash. In real implementaitons of this I've added a few random characters to the input password to detere dictionary attack.
But after thinking about it a while, I choose to enforce strong passwords at the user input level rather than in the hash calculation.
I don't think anyone has brute forced an MD5 hash by any method other than dictionary attack.
Jim
|
|
|
|
 |