Hash/Digest function
Forums
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
I don't know if this will
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
I'm closer. I was provided
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.
Hi Rob,
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