Unique string generation based on table data (Arev32)
At 09 AUG 2010 11:57:36AM Mat Kelly wrote:
I would like a unique string (e.g. md5 hash) to be created based on a table's contents. The LK and OV files for the table would then be overwritten leaving the file in which the string resides intact. The table could then have the same string generation function run on it and based on whether it is the same as the original, perform a function.
What would be an appropriate way to accomplish this?
At 09 AUG 2010 01:26PM Bob Carten wrote:
Recent OI versions have a program to do this, called RTI_MD5.
It relies on a one-time download from "http://pajhome.org.uk/crypt/md5/md5.js
You might wnat to make a version that dows not reach out and download javascript. We'll be making a version that uses the .NEt libraries to to the same thing without relying on uncontrolled scripts.
The code is below.
0001 Function RTI_MD5(method, param1,param2,param3) 0002 /* 0003 ** MD 5 is Useful for Password web authentication 0004 ** Uses a public MD5 javascript library 0005 ** See http://pajhome.org.uk/crypt/md5/index.html 0006 */ 0007 Declare Function Ole_GetWebPage 0008 $Insert Logical 0009 0010 common /rti_md5_com/ oScript,bInitialized 0011 if assigned(bInitialized) else bInitialized = '' 0012 If bInitialized = 1 Else 0013 Gosub Init 0014 End 0015 0016 If Assigned(method) Else method = '' 0017 retval = '' 0018 Begin Case 0019 Case method _eqc 'hex_md5' 0020 s = If Assigned(param1) Then param1 Else '' 0021 retval = Oscript->Run('hex_md5', s) 0022 Case method _eqc 'b64_md5' 0023 s = If Assigned(param1) Then param1 Else '' 0024 retval = Oscript->Run('b64_md5', s) 0025 Case method _eqc 'str_md5' 0026 s = If Assigned(param1) Then param1 Else '' 0027 retval = Oscript->Run('str_md5', s) 0028 Case method _eqc 'hex_hmac_md5' 0029 key = If Assigned(param1) Then param1 Else '' 0030 data = If Assigned(param2) Then param2 Else '' 0031 retval = Oscript->Run('hex_hmac_md5', key, data) 0032 Case method _eqc 'b64_hmac_md5' 0033 key = If Assigned(param1) Then param1 Else '' 0034 data = If Assigned(param2) Then param2 Else '' 0035 retval = Oscript->Run('b64_hmac_md5', key, data) 0036 Case method _eqc 'str_hmac_md5' 0037 key = If Assigned(param1) Then param1 Else '' 0038 data = If Assigned(param2) Then param2 Else '' 0039 retval = Oscript->Run('str_hmac_md5', key, data) 0040 Case method _eqc 'Random' 0041 max = If Assigned(param1) Then param1 Else '' 0042 If max = '' Then 0043 expression = 'Math.random()' 0044 End else 0045 expression = 'Math.floor(Math.random()*':max:')' 0046 End 0047 retval = oScript->Eval(expression) 0048 End Case 0049 0050 Return retval 0051 0052 Init: 0053 oScript = OLECreateInstance("MSScriptControl.ScriptControl") 0054 oScript->Language = "JScript" 0055 * Add JavaScript Library 0056 jsFile = '.\html\md5.js' 0057 OSRead jscode From jsFile Else 0058 url = "http://pajhome.org.uk/crypt/md5/md5.js" 0059 jscode = Ole_GetWebPage(url) 0060 If jscode = '' Then 0061 Call Set_Status(1,'Unable to obtain ' : Quote(url) ) 0062 Return 0063 End 0064 OSWrite jscode On jsFile 0065 End 0066 x = oScript->AddCode( jsCode ) 0067 bInitialized = "1" 0068 return