Generate JWS Keys
To sign an API call, you’ll need to follow these steps:Generate a pair of Public and Private JWS Keys
Execute this command in your terminal:private_key.pemcontaining your private keypublic_key.pemcontaining your public key
public_key.pem
private_key.pem
Upload your Public Key to the Dashboard
- Go to dashboard.fintoc.com
- Go to the API Keys tab on the side bar
- If products that require JWS are active for your organization, you’ll see a JWS Public Keys section. Click the “Add JWS Key” button and upload your JWS Public Key.
Generate Signature
Now that you loaded your Public Key to your Fintoc Dashboard, you can generate a signature based on the Private Key. This is necessary to ensure integrity and authenticity for each Transfer API call that moves money.Using our SDK
If you’re using Python or Node, our Python SDKand Node SDK automatically generates the signatures for you. Simply initialize the Fintoc client with thejws_private_key argument, and the SDK will take care of the rest:
Node
Step by step example
If you want to write your own implementation or use a different programming language, follow these steps:Prepare the payload
For JWS signature generation, we need to work with the exact JSON string that will be sent in the HTTP request. This is typically created by converting your Outbound Transfer request body object into a JSON string using your language’s JSON serializer.JSON string must be consistentWhen serializing your request body to JSON, you must use the exact same string for two purposes:
- Creating the JWS signature
- Sending as the payload in your HTTP request
Load Private Key and Configure Headers
Load your private key from the PEM file and set up the JWS headers. Headers include the signing algorithm (RS256), a unique nonce to prevent duplicated signatures, current timestamp, and critical fields specification.Preventing a replay attack
Fintoc uses thenonce and ts timestamp headers in its JWS authentication process to protect against replay attacks and ensure request integrity.
The nonce string should be a unique, random value and needs to be included in every request, making each signature distinct even if the same data is sent multiple times. Fintoc ensures that each nonce is used only once, and will reject any request that contains a duplicated nonce.
The ts timestamp records when the request was created, and Fintoc’s servers validate that it falls within a 2 minute time window to prevent the processing of outdated requests.
Together, the nonce and timestamp provide robust protection by ensuring that intercepted or tampered requests cannot be reused, safeguarding your integration against malicious activities.
Generate the Signing Input
The signing input for a JWS consists of concatenating the base64url-encodedheaders and the base64url-encoded raw_body with a period . between them, both without padding:
Generate JWS Token Signature
Once you have the signing input ready, you’ll create the cryptographic signature using your private key. The process involves:-
Sign the input using your private key with:
- RSA with PKCS1v15 padding
- Base64URL-encode the resulting signature (without padding)
- Base64URL-encode the resulting signature (without padding)
Optional: Verify JWS Token
Some libraries may re-encode JSON payloads with different spacing or key ordering, or change its encoding. To debug the signature, you can inspect the generated token at https://jwt.io to verify its content. We also recommend to double-check that the JWS Token payload is equal to theraw_body being sent in the http request.
Construct the Fintoc-JWS-Signature Header
Construct theFintoc-JWS-Signature header by concatenating the protected header and signature: