TRUXCO
    TRUXCO
    • GENERATION OF ACCESS TOKEN
    • DRIVER APP
      • REQUEST OTP
        POST
      • VERIFY OTP
        POST
      • RESEND OTP
        POST
      • DRIVER DOCUMENTS
        POST
      • UPLOAD DRIVER DOCUMENT
        POST
      • DRIVER TRIP DETAIL
        POST
      • ORDER DETAIL
        POST
      • STORE DRIVER RESPONSE
        POST
      • ORDER PTI DETAIL
        POST
      • UPLOAD PTI IMAGE
        POST
      • REMOVE PTI IMAGE
        POST
      • MARK PTI COMPLETE
        POST
      • DASHBOARD
        POST
      • TRIP ROUTE
        POST
      • FETCH LOAD JOURNEY
        POST
      • SAVE LOAD JOURNEY
        POST
      • SAVE CURRENT COORDINATES
        POST
      • ORDER DOCUMENT LIST
        POST
      • UPLOAD ORDER DOCUMENT
        POST
      • UPDATE PRE TRIP STATUS
        POST
      • TRIP ISSUE CATEGORY
        POST
      • RAISE ISSUE
        POST
      • CREATE MPIN
        POST
      • VERIFY MPIN
        POST
      • FORGOT MPIN
        POST
      • RESET MPIN
        POST
      • DELETE ORDER DOCUMENT
        POST
      • SEND GENERAL EMAIL
        POST
      • RAISED ISSUE LIST
        POST
      • DOWNLOAD DOCUMENT
        POST
      • SAVE ORDER LATEST LOCATION
        POST
      • START TRIP
        POST
    • TRANSFLOW
      • Login
      • Create Truckload
      • Add Document

    GENERATION OF ACCESS TOKEN

    Introduction#

    This document outlines the logic and process for generating the x-access-token, a secure, encrypted token used for authenticating subsequent API requests. It must be included in the request headers for all authenticated API calls.

    Token Structure#

    The token is built by concatenating the following components and encrypting the resulting string.
    userId + '|' + deviceId + '|' + token

    Parameters Explanation#

    userId: A unique identifier assigned to the user.
    deviceId: A unique identifier for the device making the request.
    token: A session or authentication token issued upon successful email OTP verification.
    Note: The userId and token are provided in the response of the Verify OTP API call.
    Sample Response with userId and token#
    {
        "responseCode": 200,
        "responseMsg": "Success",
        "driverData": {
            "id": "DR220929.1151.000001",
        },
        "token": "JHBKQWFBFJS55JZWBKEL"
    }
    
    Example (Raw Token from the above response): DR220929.1151.000001|85949418|JHBKQWFBFJS55JZWBKEL

    Client Usage#

    Include the generated token in the x-access-token header for all HTTP requests:
    x-access-token: encrypted_and_encoded_token

    Token Encryption and Encoding#

    The following are the steps for token encryption and encoding:
    1.
    Encrypt the token string (userId + '|' + deviceId + '|' + token) using AES with CBC and PKCS5Padding.
    2.
    Base64-encode the encrypted byte array.
    3.
    URL-encode the Base64 string to ensure safe transmission over HTTP.
    Output: A URL-safe, encrypted string used as the x-access-token.

    Encryption Configuration#

    ParameterValue
    Cipher AlgorithmAES/CBC/PKCS5Padding
    Encryption AlgorithmPBKDF2WithHmacSHA1
    Encryption Key61085G5GH96QW96D
    PasswordPS606AA85DRG3J93800Q9L90672IYV50
    SaltLOGISTICS

    Code Sample#

    Java#
    Library To be Used#
    import java.io.UnsupportedEncodingException;
    import java.net.URLEncoder;
    import java.security.spec.KeySpec;
    import java.util.Base64;
    
    import javax.crypto.Cipher;
    import javax.crypto.SecretKey;
    import javax.crypto.SecretKeyFactory;
    import javax.crypto.spec.IvParameterSpec;
    import javax.crypto.spec.PBEKeySpec;
    import javax.crypto.spec.SecretKeySpec;
    Initializing Static Values#
    private String ENCRYPTION_ALGO = "PBKDF2WithHmacSHA1";
    private String CYPHER_ALGO = "AES/CBC/PKCS5Padding";
    private String SALT = "LOGISTICS";
    private String PASSWORD = "PS606AA85DRG3J93800Q9L90672IYV50";
    private String ENCRYPTION_KEY = "61085G5GH96QW96D";
    Code Sample#
    private SecretKeySpec generateKey() {
        SecretKeyFactory factory = SecretKeyFactory.getInstance(ENCRYPTION_ALGO);
        byte[] saltBytes = SALT.getBytes("UTF-8");
        KeySpec spec = new PBEKeySpec(PASSWORD.toCharArray(), saltBytes, 4, 128);
        SecretKey tmp = factory.generateSecret(spec);
        return new SecretKeySpec(tmp.getEncoded(), "AES");
    }
    
    private static Cipher getCipher(int mode) throws Exception {
        Cipher cipher = Cipher.getInstance(CYPHER_ALGO);
        byte[] iv = Encryption Key.getBytes("UTF-8");
        cipher.init(mode, generateKey(), new IvParameterSpec(iv));
        return cipher;
    }
    
    public static String encrypt(String raw) {
        Cipher cipher = getCipher(1);
        byte[] encryptedVal = cipher.doFinal(raw.getBytes("UTF-8"));
        String encString = Base64.getEncoder().encodeToString(encryptedVal);
        return URLEncoder.encode(encString, "UTF-8");
    }
    Kotlin#
    Library To be Used#
    import java.net.URLEncoder
    import java.nio.charset.StandardCharsets
    import java.security.spec.KeySpec
    import javax.crypto.Cipher
    import javax.crypto.SecretKeyFactory
    import javax.crypto.spec.IvParameterSpec
    import javax.crypto.spec.PBEKeySpec
    import javax.crypto.spec.SecretKeySpec
    import java.util.Base64
    Initializing Static Values#
    private val ENCRYPTION_ALGO = "PBKDF2WithHmacSHA1"
    private val CYPHER_ALGO = "AES/CBC/PKCS5Padding"
    private val SALT = "LOGISTICS"
    private val PASSWORD = "PS606AA85DRG3J93800Q9L90672IYV50"
    private val ENCRYPTION_KEY = "61085G5GH96QW96D"
    Code Sample#
    private fun generateKey(): SecretKeySpec {
        val saltBytes = SALT.toByteArray(Charsets.UTF_8)
        val spec: KeySpec = PBEKeySpec(PASSWORD.toCharArray(), saltBytes, 4, 128)
        val factory = SecretKeyFactory.getInstance(ENCRYPTION_ALGO)
        val tmp = factory.generateSecret(spec)
        return SecretKeySpec(tmp.encoded, "AES")
    }
    
    @Throws(Exception::class)
    private fun getCipher(mode: Int): Cipher {
        val cipher = Cipher.getInstance(CYPHER_ALGO)
        val iv = ENCRYPTION_KEY.toByteArray(Charsets.UTF_8)
        cipher.init(mode, generateKey(), IvParameterSpec(iv))
        return cipher
    }
    
    fun encrypt(raw: String): String {
        val cipher = getCipher(Cipher.ENCRYPT_MODE)
        val encryptedVal = cipher.doFinal(raw.toByteArray(Charsets.UTF_8))
        val encString = Base64.getEncoder().encodeToString(encryptedVal)
        return URLEncoder.encode(encString, "UTF-8")
    }
    Swift#
    Library To be Used#
    import <CommonCrypto/CommonCrypto.h>
    Initializing Static Values#
    private let ENCRYPTION_ALGO = "PBKDF2WithHmacSHA1"
    private let CYPHER_ALGO = "AES/CBC/PKCS5Padding"
    private let SALT = "LOGISTICS"
    private let PASSWORD = "PS606AA85DRG3J93800Q9L90672IYV50"
    private let ENCRYPTION_KEY = "61085G5GH96QW96D"
    Code Sample#
    private static func generateKey() -> Data? {
        guard let passwordData = password.data(using: .utf8),
              let saltData = salt.data(using: .utf8) else { return nil }
    
        var derivedKey = Data(count: 16) // 128 bits = 16 bytes
        let result = derivedKey.withUnsafeMutableBytes { derivedKeyBytes in
            saltData.withUnsafeBytes { saltBytes in
                CCKeyDerivationPBKDF(
                    encryptionAlgo,
                    password, passwordData.count,
                    saltBytes.bindMemory(to: UInt8.self).baseAddress!, saltData.count,
                    CCPseudoRandomAlgorithm(kCCPRFHmacAlgSHA1),
                    4, // Iteration count
                    derivedKeyBytes.bindMemory(to: UInt8.self).baseAddress!, 16)
            }
        }
    
        return result == kCCSuccess ? derivedKey : nil
    }
    
    static func encrypt(raw: String) -> String? {
        guard let key = generateKey(),
              let iv = encryptionKey.data(using: .utf8),
              let dataToEncrypt = raw.data(using: .utf8) else { return nil }
    
        var outLength = Int(0)
        var cipherData = Data(count: dataToEncrypt.count + kCCBlockSizeAES128)
    
        let status = cipherData.withUnsafeMutableBytes { cipherBytes in
            dataToEncrypt.withUnsafeBytes { dataBytes in
                iv.withUnsafeBytes { ivBytes in
                    key.withUnsafeBytes { keyBytes in
                        CCCrypt(CCOperation(kCCEncrypt),
                                cipherAlgo, options,
                                keyBytes.baseAddress, key.count,
                                ivBytes.baseAddress,
                                dataBytes.baseAddress, dataToEncrypt.count,
                                cipherBytes.baseAddress, cipherData.count,
                                &outLength)
                    }
                }
            }
        }
    
        if status == kCCSuccess {
            cipherData.removeSubrange(outLength..<cipherData.count)
            let base64Encoded = cipherData.base64EncodedString()
            return base64Encoded.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
        }
    
        return nil
    }
    Modified at 2025-08-04 07:50:12
    Next
    REQUEST OTP
    Built with