Signature/tag and Signature parameter: Difference between pages
(Difference between pages)
m (1 revision imported) |
api>Admin (Created page with "Some API operations require a signature to authenticate the API client. To calculate the signature, follow this steps: * Build a string with all parameters ordered alphabeti...") |
||
Line 1: | Line 1: | ||
Some API operations require a signature to authenticate the API client. | |||
To calculate the signature, follow this steps: | |||
* Build a string with all parameters ordered alphabetically, separated by ''&'' and '''without url-encoding''' | |||
* ''' | * Get the bytes of the string, using UTF-8 encoding | ||
* Get the bytes of your private key, using UTF-8 encoding | |||
* | * Calculate the HMAC-SHA1 of the string bytes, with your private key bytes | ||
* | * Encode the signature bytes as hexadecimal digit pairs | ||
* | |||
= | == Example == | ||
'''Parameters:''' | |||
* url = <nowiki>https://www.google.com/search?q=Safe+Stamper&gws_rd=cr,ssl</nowiki> | |||
* sharedkey = 789lq9o6im682tl0m1rej34ls | |||
'''Private key: ''' | |||
* 1omnpo704w6u2ad2lxo2wrdm5 | |||
= | '''String to sign: ''' | ||
<pre> | |||
sharedkey=789lq9o6im682tl0m1rej34ls&url=https://www.google.com/search?q=Safe+Stamper&gws_rd=cr,ssl | |||
</pre> | |||
'''Content bytes''' (hexadeximal): | |||
<pre> | <pre> | ||
https://www. | 73 68 61 72 65 64 6b 65 79 3d 37 38 39 6c 71 39 |sharedkey=789lq9| | ||
? | 6f 36 69 6d 36 38 32 74 6c 30 6d 31 72 65 6a 33 |o6im682tl0m1rej3| | ||
& | 34 6c 73 26 75 72 6c 3d 68 74 74 70 73 3a 2f 2f |4ls&url=https://| | ||
77 77 77 2e 67 6f 6f 67 6c 65 2e 63 6f 6d 2f 73 |www.google.com/s| | |||
65 61 72 63 68 3f 71 3d 53 61 66 65 2b 53 74 61 |earch?q=Safe+Sta| | |||
6d 70 65 72 26 67 77 73 5f 72 64 3d 63 72 2c 73 |mper&gws_rd=cr,s| | |||
73 6c |sl| | |||
</pre> | </pre> | ||
'''Key bytes''' (hexadecimal) | |||
<pre> | |||
31 6f 6d 6e 70 6f 37 30 34 77 36 75 32 61 64 32 |1omnpo704w6u2ad2| | |||
6c 78 6f 32 77 72 64 6d 35 0a |lxo2wrdm5.| | |||
</pre> | |||
'''HMAC-SHA1''' | |||
<pre> | |||
3e e8 b6 11 39 50 c0 c8 49 4b a0 3b 4f b8 d6 16 c7 fb 9a 25 | |||
</pre> | |||
'''Signature string:''' | |||
<pre> | |||
3ee8b6113950c0c8494ba03b4fb8d616c7fb9a25 | |||
</pre> |
Revision as of 13:40, 1 December 2016
Some API operations require a signature to authenticate the API client.
To calculate the signature, follow this steps:
- Build a string with all parameters ordered alphabetically, separated by & and without url-encoding
- Get the bytes of the string, using UTF-8 encoding
- Get the bytes of your private key, using UTF-8 encoding
- Calculate the HMAC-SHA1 of the string bytes, with your private key bytes
- Encode the signature bytes as hexadecimal digit pairs
Example
Parameters:
- url = https://www.google.com/search?q=Safe+Stamper&gws_rd=cr,ssl
- sharedkey = 789lq9o6im682tl0m1rej34ls
Private key:
- 1omnpo704w6u2ad2lxo2wrdm5
String to sign:
sharedkey=789lq9o6im682tl0m1rej34ls&url=https://www.google.com/search?q=Safe+Stamper&gws_rd=cr,ssl
Content bytes (hexadeximal):
73 68 61 72 65 64 6b 65 79 3d 37 38 39 6c 71 39 |sharedkey=789lq9| 6f 36 69 6d 36 38 32 74 6c 30 6d 31 72 65 6a 33 |o6im682tl0m1rej3| 34 6c 73 26 75 72 6c 3d 68 74 74 70 73 3a 2f 2f |4ls&url=https://| 77 77 77 2e 67 6f 6f 67 6c 65 2e 63 6f 6d 2f 73 |www.google.com/s| 65 61 72 63 68 3f 71 3d 53 61 66 65 2b 53 74 61 |earch?q=Safe+Sta| 6d 70 65 72 26 67 77 73 5f 72 64 3d 63 72 2c 73 |mper&gws_rd=cr,s| 73 6c |sl|
Key bytes (hexadecimal)
31 6f 6d 6e 70 6f 37 30 34 77 36 75 32 61 64 32 |1omnpo704w6u2ad2| 6c 78 6f 32 77 72 64 6d 35 0a |lxo2wrdm5.|
HMAC-SHA1
3e e8 b6 11 39 50 c0 c8 49 4b a0 3b 4f b8 d6 16 c7 fb 9a 25
Signature string:
3ee8b6113950c0c8494ba03b4fb8d616c7fb9a25