Skip to content

Decryption failed error while generating token #10

Description

@coder-amogh

My GST Suvidha Provider (GSP) is Chartered Information Systems Private Limited (CISPL) and their documentation is here.

First question is, how to generate a PEM file? I tried following help from CISPL article and ran these two commands to obtain the PEM file:

  • $ openssl req -x509 -nodes -sha256 -days 3650 -newkey rsa:2048 -keyout AspDsc.key -out AspDsc.cer
  • $ openssl x509 -in AspDsc.cer -pubkey -noout > public_key.pem

Is this the intended way? Would appreciate help and some documentation on this.

Then I uploaded the AspDsc.cer file to CISPL portal as per their documentation and I got their email with the ASP_PASSWORD which can be used in the API calls.

My code is as follows:

with open("certs/public_key.pem") as f:
    public_key = f.read()

print("Creating session...")

session = Session(
    TEST_GSTIN, 
    client_id=CLIENT_ID, 
    client_secret=ASP_PASSWORD, 
    username=TEST_USER, 
    password=TEST_PASS, 
    public_key=public_key,
    # use the sandbox url, or production url
    # or pass-through APIs provided by GSPs
    base_url="https://gstsandbox.charteredinfo.com", 
    gsp_headers={
        "aspid": CLIENT_ID,
        "password": CLIENT_SECRET,
    },
)

print("Creating token...")

session.generate_token() # FAILS HERE

Below is complete traceback error:

Creating session...
Creating token...
{   'Data': None,
    'ErrorDetails': [   {   'ErrorCode': '1020',
                            'ErrorMessage': 'Decryption failed'}],
    'InfoDtls': None,
    'Status': 0}
Traceback (most recent call last):
  File "/Users/amoghdatar/gst-app/test-einv.py", line 34, in <module>
    session.generate_token()
    ~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/amoghdatar/gst-app/venv/lib/python3.13/site-packages/gst_irn/session.py", line 181, in generate_token
    data, app_key = _get_auth_token(self, force_regenerate_token)
                    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amoghdatar/gst-app/venv/lib/python3.13/site-packages/gst_irn/session.py", line 94, in _get_auth_token
    data = _get_data_from_response(response, encryption_key=None)
  File "/Users/amoghdatar/gst-app/venv/lib/python3.13/site-packages/gst_irn/session.py", line 58, in _get_data_from_response
    _raise_formatted_error(response, "action failed")
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amoghdatar/gst-app/venv/lib/python3.13/site-packages/gst_irn/session.py", line 45, in _raise_formatted_error
    raise RequestError(msg, err)
gst_irn.session.RequestError: ('action failed', {'Status': 0, 'ErrorDetails': [{'ErrorCode': '1020', 'ErrorMessage': 'Decryption failed'}], 'Data': None, 'InfoDtls': None})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions