NAV 2013 MD5 Hash generator

MarijnMarijn Posts: 69Member
edited 2014-07-19 in NAV Three Tier
Hello,

The goold old Navision Attain Hash 1.0.HashCalculator automation does not seem to work in NAV 2013. In 2009 and earlier NAV versions it works fine. But in 2013, when compiling the object, it throws an error: You cannot create an Automation Hash on Microsoft Dynamics NAV Server. You must create it on a client computer.

This message puzzles me and I have no idea how I would generate a hash in NAV 2013. If someonse can point me in the right direction I would be very grateful.

Comments

  • KishormKishorm Posts: 908Member
    Use the 2nd parameter of the CREATE() function - pass TRUE and this will create the automation object on the client PC instead of the service tier server.
  • MarijnMarijn Posts: 69Member
    Thank you for your answer.

    NAV 2013 does not let me save the codeunit. Compiling using F11 does not throw an error, but saving is not allowed for some reason. I am trying something like this:

    CREATE(Hash, FALSE, FALSE);
    HashString := Hash.CalculateMD5(InputString);
    CLEAR(Hash);
    EXIT(HashString);

    (Hash: Navision Attain Hash 1.0.HashCalculator)

    According to the documentation, the ClientSide boolean would be the third parameter, but I tried all combinations of TRUE and FALSE for the second and third parameters but NAV never allows saving the object. It makes me wonder whether this automation can still be used in 2013. It seems odd that something like generating a text string needs to be done clientside.
  • MarijnMarijn Posts: 69Member
    Ok. Creating a hash now works in NAV 2013. Not sure where I messed up though.

    CREATE(Hash, TRUE, TRUE);
    HashString := Hash.CalculateMD5(String);
    CLEAR(Hash);
    EXIT(HashString);
  • KishormKishorm Posts: 908Member
    Yes, should be third parameter - didn't have NAV in front of me and my memory is not what it used to be ;-)
  • krikikriki Posts: 8,768Member, Moderator
    BTW: you should stop using automation and start using .NET. NAV2013 servicetier has some problems with 32-bit automation because it is a 64-bit application.
    Regards,Alain Krikilion
    Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
    NAV TechDays 2019: 21 & 22 November 2019, Antwerp (Belgium)
  • PtaPta Posts: 25Member
    Does anybody know if there is a dot net assembly availible that I can use?
  • Luc_VanDyckLuc_VanDyck AartselaarPosts: 3,632Member, Moderator, Administrator
    Use 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Web.Security.FormsAuthentication
    MESSAGE(MD5.HashPasswordForStoringInConfigFile('a','MD5'));
    
    No support using PM or e-mail - Please use this forum. || Search is your friend
    NAV TechDays 2019: 21 & 22 November 2019, Antwerp (Belgium)
  • PtaPta Posts: 25Member
    Thanks a lot!
  • vremeni4vremeni4 Posts: 307Member
    Hi,

    I would also recommend this one as you can create MD5 hash for a file or a BLOB field.
    Name	DataType	Subtype	Length
    MD5	DotNet	System.Security.Cryptography.MD5.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    BTcon	DotNet	System.BitConverter.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    SInStream	InStream		
    HashKey	Text		50
    
    GetMD5Hash(SEntry : Record "S Entry") : Text[50]
    SEntry.CALCFIELDS(SBLOB);
    IF SEntry.SBLOB.HASVALUE THEN BEGIN
      SEntry.SBLOB.CREATEINSTREAM(SInStream);
      MD5:=MD5.Create();
      MD5.ComputeHash(SInStream);
      HashKey:= BTcon.ToString(MD5.ComputeHash(SInStream));
      HashKey:=DELCHR(HashKey, '=', '-');
      EXIT(HashKey);
    END ELSE
      EXIT('');
    


    I hope this helps someone.
    Thanks.
Sign In or Register to comment.