Skip to main content

Hash/Digest function

HI Brian & everbody else!
There are times when we would rather not propagate multiple copies of sensitive data, and unique hashes or digests would suffice. This also can help to make long fields short to save space without comrpomising uniqueness.
 
I'd like to create a custom function that calculates a SHA (or MD5) hash of a character string.
Microsoft has a crypto API that has hash functions available, but I don't have the knowledge to call it from a custom function.
Link: https://msdn.microsoft.com/en-us/library/windows/desktop/aa380252%28v=v…
 
 
So, two questions: Is it possible to access the crypto API from custom functions, and is so, how?
Any leads would be appreciated!  :)
And is there's a simpler alternative,I'm open to that!!!
 
Rob
 
 
 
 

Brian Element Tue, 06/07/2016 - 12:14

Hi Rob,

I have been looking around the web and I can't seem to get anything to work.  I can use the createobject function to create the object that is referenced in your link but I can't seem to get any of the functions to work.  I have been doing some google searches and there are lots of examples of uisng the code out there but I have had no luck using it in this scenario.  I also tried to see if I could find another approach but I wasn't able to.  You might want to send your question to IDEA as they have some programming experts that know the insides of IDEAScript much better than I do and maybe could come up with some help for you.

Brian

robgentile Tue, 06/07/2016 - 12:49

Thanks, Brian.
I tried a bunch of things before posting, I failed.  :(
I'll tap auditmation & caseware.
I wonder if it's only do-able from a full blown script, and not a custom function?
Rob
 

Brian Element Tue, 06/07/2016 - 13:11

In reply to by robgentile

Well I was trying it from a script but I couldn't seem to find the right combination.  If you do get an answer I wouldn't mind hearing about it and finding out how to do it.

Good luck.

Brian

robgentile Tue, 06/07/2016 - 13:33

I don't know if this will help, but last year I did this in an excel spreadsheet.
I  set the output cell =  BASE64SHA1("my plain text")
the code I used was this:
Public Function BASE64SHA1(ByVal sTextToHash As String)
 
 
 
    Dim asc As Object
 
    Dim enc As Object
 
    Dim TextToHash() As Byte
 
    Dim SharedSecretKey() As Byte
 
    Dim bytes() As Byte
 
    Const cutoff As Integer = 10
 
 
 
    Set asc = CreateObject("System.Text.UTF8Encoding")
 
    Set enc = CreateObject("System.Security.Cryptography.HMACSHA1")
 
 
 
    TextToHash = asc.GetBytes_4(sTextToHash)
 
    SharedSecretKey = asc.GetBytes_4(sTextToHash)
 
    enc.Key = SharedSecretKey
 
 
 
    bytes = enc.ComputeHash_2((TextToHash))
 
    BASE64SHA1 = EncodeBase64(bytes)
 
    BASE64SHA1 = Left(BASE64SHA1, cutoff)
 
 
 
    Set asc = Nothing
 
    Set enc = Nothing
 
 
 
End Function
 
 
 
Private Function EncodeBase64(ByRef arrData() As Byte) As String
 
 
 
    Dim objXML As Object
 
    Dim objNode As Object
 
 
 
    Set objXML = CreateObject("MSXML2.DOMDocument")
 
    Set objNode = objXML.createElement("b64")
 
 
 
    objNode.DataType = "bin.base64"
 
    objNode.nodeTypedValue = arrData
 
    EncodeBase64 = objNode.Text
 
 
 
    Set objNode = Nothing
 
    Set objXML = Nothing
 
 
 
End Function
 
 

Brian Element Tue, 06/07/2016 - 13:51

In reply to by robgentile

I actually found that code or something similar but it kept giving me errors when I tried to port it over to IDEAScript.  I don't know enough about those objects to tell if it is something I am doing wrong or it is just that IDEAScript can't handle it.

robgentile Wed, 06/08/2016 - 16:05

I'm closer. I was provided some code by Auditmation that let me use the crypto api to perform a trivial function. (generate a random val). 
With a little more work over the next week, I should get to the point of being able to either hash or encrypt or both. One I have it working I'll post.