首页 > 解决方案 > 将 RSA 私钥转换为字节数组

问题描述

我需要传递一个private_key_bytes: api_client.request_jwt_user_token() API中 RSA 私钥的字节内容。如何将 RSA 私钥转换为字节数组?

标签: docusignapi

解决方案


我假设您正在使用 Python 并使用我们的 SDK。这是从我们在 GitHub 上的代码示例中提取的代码片段:(这一行可以做到 - private_key = cls._get_private_key().encode("ascii").decode("utf-8") def _jwt_auth(cls): """JSON Web Token authorization""" api_client = ApiClient() api_client.set_base_path(DS_JWT["authorization_server" ])

    # Catch IO error
    try:
        private_key = cls._get_private_key().encode("ascii").decode("utf-8")
    except (OSError, IOError) as err:
        return render_template(
            "error.html",
            err=err
        )

    try:
        cls.ds_app = api_client.request_jwt_user_token(
            client_id=DS_JWT["ds_client_id"],
            user_id=DS_JWT["ds_impersonated_user_id"],
            oauth_host_name=DS_JWT["authorization_server"],
            private_key_bytes=private_key,
            expires_in=3600
        )

推荐阅读