LotusScript and MD5 Question

Does anyone have a LotusScript routine for getting an MD5 checksum of a String?–Andy

Subject: RE: LotusScript and MD5 Question

Something like this might do what you want:

Function MD5(msg$) As String
     n% = Len(msg$) - 1
     Redim B(n%) As Byte
     For i% = 0 To n%
          B(i%) = Asc(Mid$(msg$, i% + 1, 1))
     Next
     
     Dim M As Variant
     M = B
     
     Dim jsession As New JavaSession
     digest = jsession.GetClass("java/security/MessageDigest") _
     .getInstance("MD5").digest(M)
     
     For i% = 0 To Ubound(digest)
          MD5 = MD5 & Right$("0" & Hex$(digest(i%)), 2)
     Next
End Function

According to Designer Help, you need Uselsx “*javacon” in (Options), but I forgot it and the function worked anyway.

You cannot use MD5 directly on a string. MD5 works on the underlying binary data. This means that the same string can produce different results depending on the character set used to represent the string as binary data. In the code above I used the Asc function, which represents the string in the platform character set, so the result is platform-dependent.

Subject: JavaSession crashes server in batch use

This solution works fine on single usage.

I tried this in a batch agent working on several hundreds documents and first I got a StackOverFlowError and the server crashed.

Then I tried to delete all the objects after use, now the agent was able to run on a few more documents but crashed the without saying goodbye. Also declaring a global jsession didn’t work…

Server running 6.5.4 FP1 on Fedora.

So be careful with *javacon, I think they still have a lot of memory problems with java on Domino.