Using MD5 with Navision

Hi, We are looking to store a password inside the Navision database and would like to encrypt it with MD5, i.e. on validation of the password field it needs to converts the variable-length string to a 32-byte, hexadecimal string, using the MD5 algorithm. Any help appreciated. Meint

Check out CAPICOM.dll – a redistributable COM dll from Microsoft. http://msdn.microsoft.com/library/en-us/seccrypto/security/capicom_reference.asp Getting an MD5 hash from this is pretty simple:


PROCEDURE GetMD5Hash(MyPassword : Text[1024]) VAR objHash : 'CAPICOM v2.0 Type Library'.HashedData; BEGIN CREATE(objHash); objHash.Algorithm(3); // MD5... objHash.Hash(MyPassword); EXIT(ObjHash.Value); END


[edit] [Oops!] mispelled ‘Algorithm’… now it’s tested…[:I]

Hi Fritz, That has worked perfectly, thanks ever so much. We are now looking at a way to have the DLL added automatically to people’s machine and once that is working we will be well chuffed. Kind regards Meint

You could probably get the DLL inside a BLOB field and if the machine where the code is running doesn’t yet have it, extract and register it during run-time. See here for the initial idea (I have never developed it though): http://www.mbsonline.org/forum/topic.asp?TOPIC_ID=9339&SearchTerms=regsvr32

Hi Nelson, This is indeed what our developers are now trying, we are going via the example at this link: http://www.mibuso.com/howtoinfo.asp?FileID=5&Type=howto I have a feeling the permissions issue will still give us some problems, but hopefully we can resolve those as well. Regards Meint

Oh well, that was interesting. We went through all that trouble to make it work and then found that the hash did not match with the one the external app was expecting. It turned out the string needed to be converted into a byte array before you can use the hash function, and it became a pain in the backside. So, we just used the internal one, which comes installed with the Navision app. It is called NAThash.dll (in the Navision folder) and the following snippet should work: PROCEDURE EncryptString@1000000005(VAR vString@1000000000 : Text[255]); VAR Crypto@1000000002 : Automation “{A378E78B-5DB6-45E9-B598-9ED74A7CCCE1} 1.0:{439CFE8B-8413-4DCD-9BCE-B446A08EF972}:‘Navision Attain Hash 1.0’.HashCalculator”; BEGIN CREATE(Crypto); vString := UPPERCASE(Crypto.CalculateMD5(vString)); CLEAR(Crypto); END; No need to install external DLL’s (although we do check just in case some bright spark has copied the Navision client folder rather than installed it), it just works. Seven hours for something that would have taken 10 minutes with proper docs :slight_smile: Credit to Dalius, our developer, for solving it, hope it saves somebody else the pain… Perhaps one for the FAQ? Meint