Solved MD5 encryption

Discussion forum about all things Team Developer 7.x
Igor Ivanovic
Site Admin
Site Admin
Croatia
Posts: 769
Joined: 05 Mar 2017, 12:37
Location: Zagreb, Croatia

MD5 encryption

Post by Igor Ivanovic » 28 Dec 2017, 16:07

I have to encrypt some data with MD5, and I could swore that I had an example (with C# source), but can't find it anymore.
And I need it yesterday, as usual.
Could any one drive me in the right direction?

Thx.

And happy New Year everyone!
Igor Ivanovic
Image

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2166
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

MD5 encryption

Post by Jeff Luther » 28 Dec 2017, 18:33

Igor -- I have some crypto samples on my web page. Click on the link in my signature below.

Also, there are some info. and links here: https://en.wikipedia.org/wiki/MD5
and on David Ireland's CryptoSys site -- www.cryptosys.net -- (I have MD5 + other algorithms using David's cryptoSys DLL on my TD samples page) is a page of his code:
https://www.di-mgt.com.au/crypto.html

including a link to his "MD5 in Visual BASIC": https://www.di-mgt.com.au/crypto.html#MD5
with his code shown here: https://www.di-mgt.com.au/src/basMD5.bas.html

Looks like there's enough in BASIC for you to transliterate it to TD. Let us know if you need help. And if you do, zip and attach a copy of the APL/test app. that has your TD code.
Jeff Luther @ PC Design
Palm Springs, California
TD info. & samples: http://www.jeffluther.net/TD/

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 1137
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

MD5 encryption

Post by Dave Rabelink » 28 Dec 2017, 19:06

Hi Igor, Jeff,

I was busy trying to implement this using WinAPI crypt functions, which as it works will not require 3rd party components.
But till now I did not get it working, the hash is not as expected.
I do not have more time now, so maybe this can be a good starting point to get it working.

If you succeed,, please report the sample with the correct calls.

CryptographyWinApi.zip
(The sample is saved in TD61 text format)

There are a lot of samples (in c/c++ etc) which shows how to use the crypt functions which I used as starting point:

https://msdn.microsoft.com/en-us/librar ... s.85).aspx
You do not have the required permissions to view the files attached to this post.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

thomas.uttendorfer
Site Admin
Site Admin
Germany
Posts: 151
Joined: 05 Mar 2017, 17:19
Location: Munich Germany

MD5 encryption

Post by thomas.uttendorfer » 08 Jan 2018, 16:52

Hi Dave,

here is a working function set for creating MD5 from String or Binary
using only Windows API.
It's TD7.0.2 but can easily be ported back to any TD unicode Version.

Regards Thomas
You do not have the required permissions to view the files attached to this post.
Thomas Uttendorfer
[ frevel & fey ] Software-System GmbH
https://thomasuttendorfer.wordpress.com/

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 1137
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

MD5 encryption

Post by Dave Rabelink » 08 Jan 2018, 20:10

Great stuff Thomas.Thanks !!

I also uploaded your sample to the vault, for keepers ;)
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Igor Ivanovic
Site Admin
Site Admin
Croatia
Posts: 769
Joined: 05 Mar 2017, 12:37
Location: Zagreb, Croatia

MD5 encryption

Post by Igor Ivanovic » 08 Jan 2018, 21:37

Dave, Jeff, Thomas,

Sorry for not answering before, it was a really busy end of year and first new year week.
As the MD5 was a requirement mainly for my .NET project I did found a C# solution on the net and use that.
Anyway, Thomas thanks for the solution for TD, it surely will be useful for me and everybody using TD.
Igor Ivanovic
Image

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 1137
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

MD5 encryption

Post by Dave Rabelink » 10 Jan 2018, 14:37

I'm getting different results for MD5 hashes.

For this:

Code: Select all

Str2Md5HexStr( "AAA" )
I get this result in the TD sample:

Code: Select all

e15e31a4b561babd11fbadf5629886e3
But using these online MD5 generators

https://helloacm.com/md5/
https://www.md5hashgenerator.com/

the result is:

Code: Select all

e1faffb3e614e6c2fba74296962386b7
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2166
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

MD5 encryption

Post by Jeff Luther » 10 Jan 2018, 19:01

Dave: using my "1. CRC-32 checksum, and MD5, SHA-1 & SHA-256 hash" sample, available here: http://www.jeffluther.net/TD/index.html#Code_Samples

I also correctly got this for "AAA":

Code: Select all

e1faffb3e614e6c2fba74296962386b7
as you do when testing with online MD5 generators you mention.

FYT, an Attachment: I've attached a back-converted version of Igor's MD5 code and added a form etc. so we can run this as a test case. I too get Dave's incorrect value of

Code: Select all

e15e31a4b561babd11fbadf5629886e3 
when I run it. It's back-ported to v5.2 so others not on v6 or v7 can still benefit from this example, once the bug is 'wrung out' of it.
You do not have the required permissions to view the files attached to this post.
Jeff Luther @ PC Design
Palm Springs, California
TD info. & samples: http://www.jeffluther.net/TD/

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 1137
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

MD5 encryption

Post by Dave Rabelink » 12 Jan 2018, 08:11

Well I'm lost here.

Did try everything, using my and thomas sample, but I never get the expected values.

The only value I get is for an empty buffer. When passing 0 bytes as length for the buffer, the result is:

Code: Select all

d41d8cd98f00b204e9800998ecf8427e
Which is in fact the correct value for empty buffers.

I tried using ASCII(ANSI) buffers, with or without ending NULLs, but the results are never what is expected from the HASH generators out there.
And the code seems to be correct.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 1137
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

MD5 encryption

Post by Dave Rabelink » 12 Jan 2018, 09:25

I got my sample working, but I do not know why...

The buffer must first be converted to multibyte.

Then all strings passed have equal results compared to the online generators.

BUT, what happens when passing a UNICODE string?
This online generator is able to let you specify and show the bytes which are used in the buffer.
When passing a UNICODE character to the generator, the result is different compared to the TD sample.


https://cryptii.com/md5-hash


So, I'm not sure what is happening here.

Attached is my sample:
CryptographyWinApi_v2.zip
You do not have the required permissions to view the files attached to this post.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

thomas.uttendorfer
Site Admin
Site Admin
Germany
Posts: 151
Joined: 05 Mar 2017, 17:19
Location: Munich Germany

MD5 encryption

Post by thomas.uttendorfer » 12 Jan 2018, 15:55

Hi,
my former sample transformed Gutpa-internal Strings (UTF-16) to MD5.
Most online services do a conversion from UTF-8-strings which have a very different memory outline and results in a different MD5-hash.

I updated my function set to not only convert UTF16 to MD5 but also convert Gupta Strings first to UTF8 then to MD5.
With this function you get the same result as with most online services.

@Dave: Unicode is not equal to Unicode! UTF-8, UTF-7, UTF-16 and UTF-32 all have different memory outlines.
Only sometimes UTF-8 equals Ansi - only when using characters < 128.
MD5 does not "see" characters - but only their bits and bytes.

Regards Thomas
You do not have the required permissions to view the files attached to this post.
Thomas Uttendorfer
[ frevel & fey ] Software-System GmbH
https://thomasuttendorfer.wordpress.com/

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 1137
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

MD5 encryption

Post by Dave Rabelink » 15 Jan 2018, 06:55

Great Thomas !! Thanks for your efforts to get it all working !!
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Igor Ivanovic
Site Admin
Site Admin
Croatia
Posts: 769
Joined: 05 Mar 2017, 12:37
Location: Zagreb, Croatia

MD5 encryption

Post by Igor Ivanovic » 16 Jan 2018, 12:26

Great work Thomas!
I will have to check with the side I am sending MD5 signature which UTF format they expect.
Knowing this is really worth a lot...
Igor Ivanovic
Image

Adeline
France
Posts: 2
Joined: 28 Jun 2018, 09:18
Location: France

MD5 encryption

Post by Adeline » 28 Jun 2018, 09:31

Hello,

I am new to team development tool and I have to encrypt data with sha256.
I tried to look at the example you gave but I can't open the last one (the one which work).

I also find a sample which work very well here: http://samples.tdcommunity.net/ (Crypto_v10.zip). This one use the La GALIbase library. It also calls a Crypto.dll given in the sample. However, I can't find the origin of this library, it seems to not be a standard one.

I find another example (working too) but using CryptoSys API which is not free.

I am completely lost with this issue. So if anyone can help an have an idea to encrypt data without using only standard function, I will be very grateful.
(I am using Gupta team developer 6.2)

Best regards,

Adeline.

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 1137
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

MD5 encryption

Post by Dave Rabelink » 28 Jun 2018, 10:39

Adeline wrote:
28 Jun 2018, 09:31
I tried to look at the example you gave but I can't open the last one (the one which work).
The example is saved in TD 7.0 text format.

To be able to load the source in older TD versions, you need to do the steps required explained here:

http://wiki.tdcommunity.net/index.php/TDSourceVersions

IN your case you need to change the version to 4.0.50 using a text editor.

The sample can then be opened.

For your convenience I back ported the last example to TD 5.2 format (which is the first TD version using the binary datatype, which the sample needs).
Can be downloaded from here:


http://samples.tdcommunity.net/index.ph ... rch_mode=f


As for sha256:

Change the example and pass the needed ALG_ID. The list can be found here:

https://docs.microsoft.com/en-us/window ... pto/alg-id
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 0 guests