-
-
Save Fercell/e9030c07c31abc0eab75 to your computer and use it in GitHub Desktop.
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
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha1.js"></script> | |
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script> | |
<script type="text/javascript"> | |
function CalculateSig(stringToSign, privateKey){ | |
var hash = CryptoJS.HmacSHA1(stringToSign, privateKey); | |
var base64 = hash.toString(CryptoJS.enc.Base64); | |
return encodeURIComponent(base64); | |
} | |
var d = new Date, | |
expiration = 3600 // 1 hour, | |
unixtime = parseInt(d.getTime() / 1000), | |
future_unixtime = unixtime + expiration, | |
publicKey = "1234", | |
privateKey = "abcd", | |
method = "GET", | |
route = "forms/1/entries"; | |
stringToSign = publicKey + ":" + method + ":" + route + ":" + future_unixtime; | |
sig = CalculateSig(stringToSign, privateKey); | |
console.log(sig); | |
</script> |
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 calculate_signature($string, $private_key) { | |
$hash = hash_hmac("sha1", $string, $private_key, true); | |
$sig = rawurlencode(base64_encode($hash)); | |
return $sig; | |
} | |
$api_key = "1234"; | |
$private_key = "abcd"; | |
$method = "GET"; | |
$route = "forms/1/entries"; | |
$expires = strtotime("+60 mins"); | |
$string_to_sign = sprintf("%s:%s:%s:%s", $api_key, $method, $route, $expires); | |
$sig = calculate_signature($string_to_sign, $private_key); | |
var_dump($sig); | |
?> |
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
def request_params | |
expires = (DateTime.now + 1.hour).to_i | |
public_key = '1234' | |
route = 'forms/1/entries' | |
method = 'GET' | |
private_key = 'abcd' | |
string = "#{public_key}:#{method}:#{route}:#{expires}" | |
hmac = OpenSSL::HMAC.digest('sha1', string, private_key) | |
signature = CGI.escape(Base64.encode64(hmac)) | |
base_url = 'http://mydomain.com/gravityformsapi/' | |
url= "#{base_url}#{route}/?api_key=#{public_key}&signature=#{signature}&expires=#{expires}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment