def get_sign_string(source, access_secret): key = load_der_private_key( b64_decode_bytes(ensure_bytes(access_secret)), password=None, backend=default_backend() ) signed_bytes = key.sign( ensure_bytes(source), padding.PKCS1v15(), hashes.SHA256() ) signed_base64 = b64_encode_bytes(signed_bytes) signature = ensure_string(signed_base64).replace('\n', '') return signature
def get_sign_string(source, access_secret): if platform.system() != "Windows": from Crypto.Signature import PKCS1_v1_5 from Crypto.Hash import SHA256 from Crypto.PublicKey import RSA key = RSA.importKey(b64_decode_bytes(ensure_bytes(access_secret))) h = SHA256.new(ensure_bytes(source)) signer = PKCS1_v1_5.new(key) signed_bytes = signer.sign(h) signed_base64 = b64_encode_bytes(signed_bytes) signature = ensure_string(signed_base64).replace('\n', '') return signature else: message = "auth type [publicKeyId] is disabled in Windows " \ "because 'pycrypto' is not supported, we will resolve " \ "this soon" raise exceptions.ClientException(error_code.SDK_NOT_SUPPORT, message)
def get_md5_base64_str(content): m = hashlib.md5() content_bytes = ensure_bytes(content) m.update(ensure_bytes(content_bytes)) return ensure_string(b64_encode_bytes(m.digest()).strip())
def get_sign_string(source, secret): source = ensure_bytes(source) secret = ensure_bytes(secret) h = hmac.new(secret, source, hashlib.sha1) signature = ensure_string(b64_encode_bytes(h.digest()).strip()) return signature
def get_md5_base64_str(content): return ensure_string(b64_encode_bytes(_get_md5(content)).strip())