将 RSA 私钥转换为字节数组

Convert RSA private key to bytes array

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

我假设您正在使用 Python 并使用我们的 SDK。 这是从 GitHub 上的 code examples 中提取的代码片段: (这条线做到了 - 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
        )