Last active
November 15, 2023 02:15
-
-
Save zironycho/960059cbc1ab30a4cd617801e08c8c03 to your computer and use it in GitHub Desktop.
make signature for api
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
import sys | |
import base64 | |
import hmac | |
from hashlib import sha1 | |
from datetime import datetime, timezone | |
# https://docs.aws.amazon.com/ko_kr/AmazonS3/latest/userguide/RESTAuthentication.html | |
def make_signature(timestamp, company, endpoint, method, secret_key): | |
string_to_signin = '\n'.join([ | |
str(int(timestamp)), | |
str(company), | |
str(endpoint), | |
str(method), | |
]) | |
return base64.b64encode(hmac.new( | |
secret_key.encode('utf-8'), | |
string_to_signin.encode('utf-8'), | |
sha1 | |
).digest()).decode('utf-8') | |
if __name__ == '__main__': | |
timestamp = int(datetime.now(timezone.utc).timestamp()) | |
company, endpoint, method, secret_key = sys.argv[1:] | |
print(f'timestamp: {timestamp}') | |
print(f'sources: {company}, {endpoint}, {method}, {secret_key}') | |
signature = make_signature(timestamp, company, endpoint, method, secret_key) | |
print(f'signature: {signature}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output: