Skip to content

Commit

Permalink
basic use of rsa library to decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Chen1 committed Feb 20, 2024
1 parent 6f0b438 commit 7439d7c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion swan/api/swan_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import web3
import logging
import os
import rsa
import base64
import json

from swan.api_client import APIClient
from swan.common.constant import *
Expand Down Expand Up @@ -114,10 +117,16 @@ def fetch_task_details(self):
# PRIVATE KEY GIVEN THROUGH .ENV FILE
private_key = os.environ.get("PRIVATE_KEY")
try:
private_key = rsa.PrivateKey.load_pkcs1(private_key)
task_details = self._request_without_params(
GET, TASK_DETAILS, self.orchestrator_url, self.token
)
return task_details
encrypted_token = task_details.get('token')
decrypted_token = rsa.decrypt(base64.b64decode(encrypted_token), private_key)
decrypted_token = decrypted_token.decode()
task_details['token'] = decrypted_token
task_details_json = json.dumps(task_details)
return task_details_json
except:
logging.error("An error occurred while executing fetch_task_details()")
return None

0 comments on commit 7439d7c

Please sign in to comment.