String.tohash()

How does this function exactly work?

It looks like its using sha-256 for the hashing, which is what we need.

However output seems like base64, is it somehow possible to have output in hex?

Also wondering how to do this in the plugin, what do we fill in parameter ‘hash_encoding’ to get the result in hex format?

@Wim, @Wilko, could you help?

Sounds like missing plugin documentation… :slight_smile:

The hash_encoding parameters accepts “base64” or “hex”. If you set it to null or an empty string, it defaults to base64. If you set it to any other non-empty string, it will return the following error: must be “base64” or “hex”.

Hi Wim,

Thats great thanks for your answer.

Is is also possible to specify the hash_encoding parameter in the tohash() function?

I tried “test”.tohash([<“hash_encoding”, “hex”>]) but that does not work.

Hi Arnold, I didn’t know that function even existed. But I checked, and you can do something similar with the function. The first parameter is 1, 256, or 512 for the SHA type. The second parameter is the optional encoding name, and the third is base64 or hex. For example:

“test”.tohash(256,string:getnull(),“hex”)

Beware that this function does not have an implementation in SQL, which means the hash is always calculated in the web application. This also means that if you were to use it in the Where or the Sort of a query, things will get really slow because all data will need to be fetched from the database first.

Hi Wim,

Thanks again I think that’s exactly what we need.

And now this plugin is also documented :slight_smile: