TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CADmium on November 17, 2008, 04:32:41 AM
-
Has anyone a (Auto) Lisp-routine to get the MD5-Hash from a String ? (or other Lispcode like http://en.wikipedia.org/wiki/MD5#Pseudocode )
-
You can do this via .net easier.. i.e
I attached a compiled dll for you to try.
namespace LispBase
{
public class Commands
{
//(MD5 "MD5")
[LispFunction("MD5")]
public static ResultBuffer test1(ResultBuffer args)
{
ResultBuffer retList = new ResultBuffer();
try
{
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
if (args == null)
{
retList.AddErr("Null Argument");
return retList;
}
if (args.GetCount() == 0)
{
retList.AddErr("To Few Arguments");
return retList;
}
if (args.GetCount() == 2)
{
retList.AddErr("To Many Arguments");
return retList;
}
string StrMd5 = HashString(Convert.ToString(args.AsArray()[0].Value));
retList.AddString(StrMd5);
}
catch (System.Exception ex)
{
retList.AddErr(ex.Message);
}
return retList;
}
private static string HashString(string Value)
{
System.Security.Cryptography.MD5CryptoServiceProvider MD5 =
new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] data = System.Text.Encoding.ASCII.GetBytes(Value);
data = MD5.ComputeHash(data);
StringBuilder sb = new StringBuilder(data.Length);
for (int i = 0; i < data.Length; i++)
sb.Append(data[i].ToString("x2").ToLower());
return sb.ToString();
}
}
}
-
string StrMd5 = HashString(Convert.ToString(args.AsArray()[0].Value));
nice protection against someone silly like me who would try to pass an integer .. :)
-
Heh! When in doubt, convert to string :laugh:
-
Many thanks.
I know, that windows has such a function inside and that isn't a problem to use it via .Net ,but I'm looking for a Code only in autolisp, without any other dll and arx .... If somebody has such a Routine.... ??
-
Sorry, I don’t know of any off hand, looks like it would be fun to write one though.