예제 #1
0
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
예제 #2
0
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)
예제 #3
0
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())
예제 #4
0
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
예제 #5
0
파일: md5_tool.py 프로젝트: P79N6A/xfz
def get_md5_base64_str(content):
    return ensure_string(b64_encode_bytes(_get_md5(content)).strip())