AES+sha256 encrypted signature authentication scheme. AES is used to encrypt request parameters and response data, while sha256 digest signatures applied to both request parameters and response data.airudderredduria. To obtain production keys, please contact us in advance.The examples are in Python; the actual implementation language is flexible.
def aes_encrypt(text, aeskey):
"""aes encryption"""
if isinstance(text, str):
text = text.encode("utf8")
enc_secret = AES.new(aeskey.encode("utf-8"), AES.MODE_ECB)
# ECB Padding: ECB requires the plaintext length to be multiple of the block size, so the text must be padded accordingly. This document specifies zero-padding(\0) for alignment.
tag_string = text + (AES.block_size - len(text) % AES.block_size) * b"\0"
cipher_text = base64.b64encode(enc_secret.encrypt(tag_string))
return cipher_text
def aes_decrypt(text, aeskey):
"""aes decryption"""
if isinstance(text, str):
text = text.encode("utf8")
dec_secret = AES.new(aeskey.encode("utf-8"), AES.MODE_ECB)
raw_decrypted = dec_secret.decrypt(base64.b64decode(text))
clear_val = raw_decrypted.rstrip(b"\0")
return clear_valutf-8 and take the lowercase hexadecimal value of its sha256 digest.The examples are in Python; the actual implementation language is flexible.
def sha256_sign(text):
"""sha256 signature"""
if isinstance(text, str):
text = text.encode("utf8")
return hashlib.sha256(text).hexdigest()Is-Encrypted 1 in the request HEADER to mark whether it is encryptedSigned xxx in the request HEADER to mark the sha256 signature value{
"Is-Encrypted": "1",
"Signed": "6956d7af4c89b89f19f9ae0a8be4bcf12abe7c6ed893691733f3480ad3f3aabc"
}sha256 signature of the original data, place it in the request header, and send the request.Is-Encrypted 1 in the response HEADER to mark whether it is encryptedSigned xxx in the response HEADER to mark the sha256 signature value