質問

アマゾンの製品APIは、今私は、Pythonをushing生成しようとしているすべての要求に署名が必要です。

私は上のハングアップを取得ステップは、このいずれかです。

「:プログラミング言語のドキュメントやコードサンプルを参照して、この手順の詳細については1234567890秘密アクセスキー。 『

ダミーの』私たちの持つ上記の文字列を使用してSHA256ハッシュアルゴリズムでRFC 2104準拠のHMACを計算します」

文字列と(この場合は1234567890で)秘密鍵を考えるとどのように私は、Pythonを使用して、このハッシュを計算していますか?

----------- UPDATE -------------

HMAC.newを使用して最初のソリューションは、しかし、私は、彼らがよりも異なる結果を取得しています正しい見えます。

http://docs.amazonwebservices.com/ AWSECommerceService /最新/ DG / index.htmlの?残り-signature.htmlする

あなたは秘密鍵1234567890をハッシュしたときに、Amazonの例によれば、以下の文字列

GET
webservices.amazon.com
/onca/xml
AWSAccessKeyId=00000000000000000000&ItemId=0679722769&Operation=I
temLookup&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReview
s&Service=AWSECommerceService&Timestamp=2009-01-01T12%3A00%3A00Z&
Version=2009-01-06
'Nace+U3Az4OhN7tISqgs1vdLBHBEijWcBeCqL5xN9xg='

あなたは、次のシグネチャを取得する必要があります '411a59403c9f58b4a434c9c6a14ef6e363acc1d1bb2c6faf9adc30e20898c83b'

私はこれを取得しています

役に立ちましたか?

解決

import hmac
import hashlib
import base64
dig = hmac.new(b'1234567890', msg=your_bytes_string, digestmod=hashlib.sha256).digest()
base64.b64encode(dig).decode()      # py3k-mode
'Nace+U3Az4OhN7tISqgs1vdLBHBEijWcBeCqL5xN9xg='

他のヒント

>>> import hmac
>>> import hashlib
>>> import base64
>>> s = """GET
... webservices.amazon.com
... /onca/xml
... AWSAccessKeyId=00000000000000000000&ItemId=0679722769&Operation=ItemLookup&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReviews&Service=AWSECommerceService&Timestamp=2009-01-01T12%3A00%3A00Z&Version=2009-01-06"""
>>> base64.b64encode(hmac.new("1234567890", msg=s, digestmod=hashlib.sha256).digest())
'Nace+U3Az4OhN7tISqgs1vdLBHBEijWcBeCqL5xN9xg='
import hmac
import hashlib
import base64

digest = hmac.new(secret, msg=thing_to_hash, digestmod=hashlib.sha256).digest()
signature = base64.b64encode(digest).decode()

私は、これは愚かな音を知っていますが、事故によってあなたの秘密の末尾にスペースがないことを確認します。

http://docs.python.org/library/hashlibから。 HTML位モジュールhashlibする(変更ビット):

import hashlib
secretKey = "1234567890"
m = hashlib.sha256()

# Get string and put into givenString.

m.update(givenString + secretKey)
m.digest()
あなたがのpython3を使用してAWSのcognitoにユーザーをサインアップしようとしている場合は、

は、次のコードを使用することができます。

#For the SecretHash 
import hmac
import hashlib
import base64   

//Please note that the b in the secretKey and encode('utf-8') are really really important. 
secretKey = b"secret key that you get from Coginito -> User Pool -> General Settings -> App Clients-->Click on Show more details -> App client secret  "
 clientId = "Coginito -> User Pool -> General Settings -> App Clients-->App client id"
 digest = hmac.new(secretKey,
              msg=(user_name + clientId).encode('utf-8'),
              digestmod=hashlib.sha256
             ).digest()
 secrethash = base64.b64encode(digest).decode()

上記では、ユーザ名user_nameのは、あなたがcognitoに登録したいユーザーと同じである。

client = boto3.client('cognito-idp', region_name='eu-west-1' )

response = client.sign_up(
                    ClientId='Coginito -> User Pool -> General Settings -> App Clients-->App client id',
                    Username='Username of the person you are planning to register',
                    Password='Password of the person you are planning to register',
                    SecretHash=secrethash,
                    UserAttributes=[
                        {
                            'Name': 'given_name',
                            'Value': given_name
                        },
                        {
                            'Name': 'family_name',
                            'Value': family_name
                        },
                        {
                            'Name': 'email',
                            'Value': user_email
                        }
                    ],
                    ValidationData=[
                        {
                            'Name': 'email',
                            'Value': user_email
                        },
                    ]
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top