Last active
April 3, 2023 06:27
-
-
Save acrosman/ff85c0a180caa0bc0dc2d83bbd9e7a80 to your computer and use it in GitHub Desktop.
A PHP function to sign dynamic parameters for FormAssembly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function prepareFormAssemblyQueryString(array $parameters, $salt, $expire_timeout) { | |
$parts = []; | |
$signString = ''; | |
foreach($parameters as $key => $value) { | |
$signString .= $key . $value; | |
$parts[] = rawurlencode($key) . '=' . rawurlencode($value); | |
} | |
$expireTime = time() + $expire_timeout; | |
$signString .= 'expire' . (string)$expireTime; | |
// hmach the signature string | |
$hash = hash_hmac('sha256', $signString, $salt, TRUE); | |
$sig = rawurlencode(base64_encode($hash)); | |
$parts[] = 'signature=' . $sig; | |
$parts[] = 'expire=' . (string)$expireTime; | |
$queryString = implode('&', $parts); | |
return $queryString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment