Page 2 of 2
Re: MD5FingerPrint in Unicode
Posted: Mon Jan 05, 2015 5:23 pm
by luis
STARGÅTE wrote:
The MD5Fingerprint() is a function for a memory buffer (not directly for strings!).
So, it is not the job of this memory function to "change" the format of the buffer.
Yep, that's the point, I agree. What you store in the memory buffer it's up to you.
STARGÅTE wrote:It's a bad habit to use strings as memory buffer.
When compiling to both unicode and ascii is more cumbersome, else can have its advantages (you can use string commands on that buffer, it auto-deallocates itself when leaving the procedure, etc.).
As long as you know what you are doing, it's not necessarily a bad habit IMO.
Re: MD5FingerPrint in Unicode
Posted: Mon Jan 05, 2015 11:42 pm
by Little John
STARGÅTE wrote:Little John wrote:Howevr, IMHO PB's built-in MD5Fingerprint() function just should provide the option to pass a format parameter.
Then it wouldn't be necessary for us to write a wrapper in order to get this important option.
( But this is a feature request by me. I can't see a bug here. )
The MD5Fingerprint() is a function for a
memory buffer (not directly for strings!).
So, it is not the job of this
memory function to "change" the format of the buffer.
That's why
Little John wrote:( But this is a feature request by me. I can't see a bug here. )
My feature request was to extend the functionality of PB's MD5Fingerprint() function.
STARGÅTE wrote:This is also a rule for all other functions such as:
CRC32Fingerprint, SHA1Fingerprint, AESDecoder, AESEncoder, Base64Decoder, Base64Encoder and so on.
Yes, I know.
And we also know, that people post the same problems with these functions here on the forum again and again for years.
Why not extend those functions, in order to make them more flexible?
STARGÅTE wrote:It's a bad habit to use strings as memory buffer.
I think it depends on the context.
In some cases it's certainly a bad idea (e.g. when the buffer contains zeros), in other cases it might have its advantages.
If it is actually a bad habit, then at least examples for doing so should be removed from the PB docs.

E.g.:
http://www.purebasic.com/documentation/ ... coder.html
http://www.purebasic.com/documentation/ ... coder.html
http://www.purebasic.com/documentation/ ... print.html
(These examples are showing
incorrect use of strings as buffers!)
BTW: For important stuff, it's best not to use MD5 at all.
http://www.purebasic.fr/english/viewtop ... 37&t=61364
Re: MD5FingerPrint in Unicode
Posted: Fri Feb 13, 2015 10:06 am
by Tranquil
Hello Forum.
I have the same problem as the starter of this thread and I did not found a solution for this right now.
To convert the sting to an ASCII string can not be the solution. For eg I want the hash of the following character: "Æ", how do I calculate this?
It can not be stored in a one Ascii Byte, so what to do?
Re: MD5FingerPrint in Unicode
Posted: Sat Feb 14, 2015 3:26 pm
by Tranquil
Got it!
Converting to UTF8 in Unicode Mode gives the correct answers.
This is what I use now for further projects. It returns the always correct value, even for unicode strings.
Code: Select all
pwd$="ÝßÕýý"
*mem = AllocateMemory(StringByteLength(pwd$,#PB_UTF8))
PokeS(*mem,pwd$,-1,#PB_UTF8 | #PB_String_NoZero)
Debug SHA1Fingerprint(*mem,MemorySize(*mem))
Re: MD5FingerPrint in Unicode
Posted: Fri Aug 14, 2015 4:36 pm
by Trond
You need to call FreeMemory(*mem), else your program will take up a tiny bit more memory every time it runs that code.