I found some code on this page : http://krishhdax.blogspot.co.il/2014/07/useful-functions-to-use-in-ax2012.html
to calculate a MD5 cash in X++
I works fine, but if I have a string with special characters it gives a different hash code then for example md5 via php gives me, I'm using this to check a string coming from a webservice call.
Does anyone have experience with this ?
This is the code I use :
public static str CalculateHash(str tb)
{
// code taken from : krishhdax.blogspot.co.il/.../useful-functions-to-use-in-ax2012.html
str s;
ClrObject obj;
ClrObject md5;
System.Text.StringBuilder sBuilder;
ClrObject clrStr;
ClrObject clrStrObject;
System.Exception clrException;
System.Array resultByteArray;
int i;
int arrayLength ;
InteropPermission perm;
perm = new InteropPermission(InteropKind::ClrInterop);
perm.assert();
try
{
obj = System.Text.Encoding::get_ASCII().GetBytes(tb);
md5 = System.Security.Cryptography.MD5::Create();
resultByteArray = md5.ComputeHash(obj);
//BP deviation documented
sBuilder = new System.Text.StringBuilder();
arrayLength = resultByteArray.get_Length() ;
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (i = 0; i <arrayLength; i++)
{
clrStrObject = resultByteArray.GetValue(i);
clrStr = clrStrObject.ToString('x2');
sBuilder.Append(clrStr);
}
// Return the hexadecimal string.
s = sBuilder.ToString();
}
catch (Exception::CLRError)
{
//BP deviation documented
clrException = CLRInterop::getLastException();
s = clrException.get_Message();
error(s);
throw error("@SYS106158");
}
CodeAccessPermission::revertAssert();
return s;
}
*This post is locked for comments
I have the same question (0)