Help

Re: Hashing Md5 using scripting

5259 6
cancel
Showing results for 
Search instead for 
Did you mean: 
Krishna_S_Bouka
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi everyone
I am trying to create a hash of a record using md5. I am fairly new to script but I am willing to learn. does anyone have an idea of how to do that?

Thank you

9 Replies 9

There are at least six pathways any recommendation could lead; help me find the right pathway by sharing what you would do with a hashed record.

Hi Bill, sorry I just saw your message.
Yes so what i want to do is the following
I have a table with a concatenated field. I would like to generate a hash for the concatenated field

The table looks like something like this:

<iframe class="airtable-embed" src="https://airtable.com/embed/shr9DMj7PirI4dY6e?backgroundColor=teal&viewControls=on" frameborder="0" onmousewheel="" width="100%" height="533" style="background: transparent; border: 1px solid #ccc;"></iframe>

Sorry i don’t know how to copy a view of the base.

The concatenated value is to be hashed on the last column.

Any idea how this could be achieved?
Thanks

Right, I understand what you would do to the target field. I don’t understand the reason for doing so.

If you are trying to conceal a password, for instance, my advice would be very different from using this approach to generate an immutable key value.

My advice is gated by the objective.

actually, the purpose is to produce a hash that will be added to a url to produce a unique url for SSO.
I am happy to concatenate the differente values, no pb there, my issue is about hashing a parameter using md5
I can integrate that hash to the url parameter. I hope the objective is clearer. Thanks

Okay, and is the purpose to encode the URL to avoid all of the issues with a URL parameter that is unruly and unable to meet the requirements of HTTP addresses? If so, why not simply encode the parameter?

In any case, computing an MD5 can be done with a script action, although not recommended because MD5’s are pretty intensive. The better approach might be to use a Script Block like this:

/*

   ***********************************************************
   ScriptBloqs - MD5
   Copyright (c) 2021 by Global Technologies Corporation
   ALL RIGHTS RESERVED
   ***********************************************************
   
*/

output.markdown('# MD5 Example');

// load the md5 library
// not included because of space limitations...

// get the name of the table
let table = base.getTable("Airdrop");

// get the records from this table
let records = await table.selectRecordsAsync();

// Update the records
for (let record of records.records) {

    if (record.getCellValue("MD5 Source"))
    {

        output.inspect(record.getCellValue("MD5 Source"));

        // compute the md5 value
        thisMD5 = MD5(record.getCellValue("MD5 Source"));
        output.markdown("MD5: " + thisMD5);

        await table.updateRecordAsync(record, {
            "MD5 Target" : thisMD5,
        });

    }
}

Note that this code is not functional until you include this library at the top of the script itself. Note - if you obfuscate the library with a tool like this, the performance will double.

When this block is executed on this example data, you will get the MD5 values as desired.

image

Krishna_S_Bouka
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi Bill, sorry for the late reply! I appreciate your help on this issue.
Many thanks

No worries. Almost everything I say is eventually found to be useful well into the future. :winking_face: But 7 months is like 25 Internet years and 250 microservice years. :winking_face:

Hey @Bill_French (big fan here).
So I have an airtable DB with thousands of PDFs (1 per record) and I want a way to automatically detect duplicates. My assumption is that the cleanest way would be to calculate hashes for each PDF and then compare them/delete duplicate records.

You describe a way above that might work, however this wouldn't trigger atuomatically. And script steps in automations can't use libraries. Correct? Is there a way?

> ... however this wouldn't trigger atuomatically. And script steps in automations can't use libraries.

They can if you include the library as code in the script itself. The example above uses this approach and it works, therefore it also works in an automation.