hashlib.md5() TypeError: Unicode-objects must be encoded before hashing

后端 未结 7 1239
自闭症患者
自闭症患者 2020-12-09 15:16

I am new to coding and have ran into a problem trying to encode a string.

>>> import hashlib
>>> a = hashlib.md5()
>>> a.update(\'         


        
7条回答
  •  臣服心动
    2020-12-09 15:46

    For Python3 the following worked.

    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()
            signature = base64.b64encode(digest).decode()
    

    The username user_name in the above is same as the user that you want to register in the cognito.

提交回复
热议问题