Sha256 keyword modifier


(Gavin Boyd) #1

Matrix Version: 5.4.0.2

Does Matrix have SHA256 capabilities? I can see SHA1 keyword only.


(Bart Banda) #2

What specific functionality around SHA256 are you after?


(Gavin Boyd) #3

The API which we are using requires you to use sha256 as part of signing requests. The steps for signing a request are:

  1. Increment the token nonce so it is a higher number than the previous request. The increments do not need to be sequential.
  2. Collect all the parameters you need to send for your request into a key/value array, include the token key and nonce.
  3. Extract only the values from the parameters array and add the token secret.
  4. Order these values alphabetically, they must be compared as strings rather than numbers.
  5. Concatenate the values, joining by the ‘-’ character.
  6. Generate the signature by hashing this string using the sha256 algorithm.
  7. Add the secret to the parameters array.
  8. Submit the request using either GET or POST.

(Bart Banda) #4

Thanks for explaining. So would a ^SHA256 keyword modifier similar to the SHA1 be useful?


(Tbaatar) #5

Hi Bart,

Can you confirm if SHA256 works/exists for Matrix 5.4+?
Wanting to test out the Cloudinary API/Widget and the Media Gallery requires generating auth signature in order to connect.

Thanks,
Tuguldur


(John gill) #6

Not as of 5.5.1.5 at least.

$ grep -n  "sha\|md5" general/text.inc
959:            case "md5":
960:                    return md5($text);
962:            case "sha1":
963:                    return sha1($text);
2041:                           $hash = '<!-- x'.md5($ssjs_block).strlen($ssjs_block).'x -->';

(Bart Banda) #7

Yea we don’t have a modifier for that. But perhaps you could do it with SSJS and using something like https://github.com/emn178/js-sha256 ?