Implementazione open-source del protocollo di Strong Customer Authentication di Poste Italiane, (https://posteid.poste.it), lato client.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

25 lines
658 B

import hmac
import json
from base64 import b64encode, urlsafe_b64encode
from hashlib import sha256
def sha256_base64(payload):
out = payload.encode('utf-8')
out = sha256(out).digest()
out = b64encode(out)
return out.decode('utf-8')
def hmac_sha256(key, message):
hm = hmac.new(key.encode('utf-8'), digestmod=sha256)
hm.update(message.encode('utf-8'))
digest = hm.digest()
return urlsafe_b64encode(digest).decode('utf-8').replace('=', '')
class RequestFailure(Exception):
def __init__(self, message, ans, error_code=None):
super().__init__(message)
self.ans = ans
self.error_code = error_code