Card Encryption

The card details(card number, expiry month, expiry year, cvv) can be encrypted before passing to Juspay using the asymmetric cryptographic algorithm.

  • The public key will be shared by Juspay which can be used for encryption.
  • Encrypt the card details using the shared public key. The sample code snippet is given below.
  • Prepend "enc-" to the encrypted detail.
  • Pass the details to Juspay in the transaction call.

📘

Encryption algorithm and key size

Algorithm: RSA/ECB/PKCS1Padding
Key Size: 2048 bit

Required inputs are given below

Field

Description

Sample Data

card_encoding_version

The version of encryption

2021-01-21

client_enc_key_id

The Key id provided by Juspay. Required for merchant specific RSA keys

9999

card_number

Encrypted card number. Prepend "enc-" to the encrypted detail

enc-13df32hfjhrf

card_exp_month

Encrypted card expiry month. Prepend "enc-" to the encrypted detail

enc-ytgrfdsxfcvbjm

card_exp_year

Encrypted card expiry year. Prepend "enc-" to the encrypted detail

enc-kiujytgrfdxcvbn

card_token

The card token obtained in the response of list card. Required for saved card transaction.

tkn_b095fb039015642b4b8a80eac132368b0

card_security_code

Encrypted card security code. Prepend "enc-" to the encrypted detail

enc-jhkhgdfszxcf

Sample Code Snippet for Encryption

public String encryptRSA(String publicKey, String content) {

    try {
        final String algorithm = "RSA/ECB/PKCS1Padding";

        publicKeyContent = publicKeyContent
                .replace("-----BEGIN PUBLIC KEY-----\n", "")
                .replace("-----END PUBLIC KEY-----", "");

        KeyFactory keyFactory = KeyFactory.getInstance("RSA");

        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.decode(publicKeyContent, Base64.DEFAULT));
        Key publicKey = keyFactory.generatePublic(keySpec);

        Cipher cipher = Cipher.getInstance(algorithm);
        cipher.init(Cipher.ENCRYPT_MODE, publicKey);

        byte[] encrypted = cipher.doFinal(content.getBytes());

        return Base64.encodeToString(encrypted, Base64.NO_WRAP);
    } catch (Exception e) {
        
    }

    return "";
}
Sample cURL for transaction API
curl --location --request POST 'https://sandbox.juspay.in/txns' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'merchant_id=merchant_success' \
--data-urlencode 'order_id=JP163552819' \
--data-urlencode 'payment_method_type=CARD' \
--data-urlencode 'format=json' \
--data-urlencode 'card_number=enc-Lkhtaxi67b5ycJUa5HK3vfsr1xYiYtRYK0XxnIR2wmo3K4dkovKD3yvrjVlLA99/8qKjxXpasbKDGpJfm+Mx+CR7dKaTgUfvN04pE54kbMQPYRUgHwZ2S2vl8ntxE/5mT9Fu2NfoC8s8xKbFxNQ8tiIQ4SgobS7a95+U/TvJ3iwEPKQwm08SZIKfW+/vpQbYNWC73rFdi59aS9H7aH9d3WyfGfVezxYRF0iRTBgbDUsnvl50ZMRJGPx+hRHgfsktmBfrhfDm9mYaD/0qEYAMXOmfBAk6ruVW5xR7To2Ce/0BBb3fPKIhtYnYNLeFq1L1gJiIdrONCdZxIdfhperwTA==' \
--data-urlencode 'card_exp_month=enc-DmPCnxXjsVcq6jfgsSu8etI1QT4qGyjy8uv0IAIhNLUkF3Mesd0eWIvGstBBa5xiYR5+48mUwrVYH5IsqBMmhqkjkyQ5LjG5+h9AesYUB+eVI6p06Bc4Qr+UBU02gjG/Ex1WmbbD7YQ3FpvWbS/slOv2+zF0Qop5dSoNiY9QdkSD5g18LvVi2d5EGzPA2BoUfHt84btom2zXs/mdMvFStqk0J0S2LlBqUIDVnNYKwQ+54b792Szq+qaiaZqRUWwuHE8RkAiMrU8QkdpjNs5Fi5RuKcRVo1FMfW4s5xocjLp9mkDDW7uuYyYyVQxIXPyTSdwZTNWet/qflh72fDrMlw==' \
--data-urlencode 'card_exp_year=enc-eaOEGCPdV4SYR6gyedXlvHYPcS/pUxo9oyvd8kzpp5/bERyxzzj3KRvQhTk+Vpr5aMGgT+oxkGW8K3JzdVS12AULN4jpZBa9d13HJkj5LTBdsxwivO4vqtDk9y9skDivHBvwRREKB/nzG6DGMYUfM62Pklkt9/TJjqrGTOhOgDbk0C4oTnObiJvzi9EFnwAC/+8usWLEv85BA4p8pGswPY1SZaR/ZlF3PG+vqJoTwu5AKd1WcUbfrl4//XeaCIMb+L3OZ+SvlsE1lNvmOzQV98P1jdijTKjEt8U4nj5wh8uJqssTqr6iKkFCcCanIcATFTEsA0LcWW4BPM4OHlzyHw==' \
--data-urlencode 'card_security_code=enc-eXiNSDcGRnIPzDF2bZqAxNFBIF1FxOdBZ3tmdQn0lcxc4aDucQwefqqzSiYQK1xkPMWw27mKXQsAclwYDQSWAslytyJQYyWFeD0e1eAOVIrf5oqFKxFhKCpj2eeIOglZ9GPRmbu9zwpuVjM68LfUQEDyymwrooQkGILFszxhcKTqMx8q8XExWzRbOufO85z4W7UcbnKCL6u/oOvo+J92bDchRh/JMzDoYLgtdhjUXhfMw92t7TCP3aFjitIOPu9PdQE4N8Fs26GSTrfxmTnvIDZSG5GvndQXoGgg9wA4pXXmb4Sd6qYhstIKzR4dX8Csctc5+H8oOd82du6P3jnPUw==' \
--data-urlencode 'redirect_after_payment=true' \
--data-urlencode 'name_on_card=test' \
--data-urlencode 'card_encoding_version=2021-01-22' \
--data-urlencode 'save_to_locker=true' \
--data-urlencode 'payment_method=MASTER'
curl --location --request POST 'https://sandbox.juspay.in/txns' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'merchant_id=merchant_success' \
--data-urlencode 'order_id=JP1635844655' \
--data-urlencode 'payment_method_type=CARD' \
--data-urlencode 'format=json' \
--data-urlencode 'redirect_after_payment=true' \
--data-urlencode 'card_token=tkn_b095fb09015642ee23r8a80eac166168b0' \
--data-urlencode 'card_security_code=enc-eXiNSDcGRnIPzDF2bZqAxNFBIF1FxOdBZ3tmdQn0lcxc4aDucQwefqqzSiYQK1xkPMWw27mKXQsAclwYDQSWAslytyJQYyWFeD0e1eAOVIrf5oqFKxFhKCpj2eeIOglZ9GPRmbu9zwpuVjM68LfUQEDyymwrooQkGILFszxhcKTqMx8q8XExWzRbOufO85z4W7UcbnKCL6u/oOvo+J92bDchRh/JMzDoYLgtdhjUXhfMw92t7TCP3aFjitIOPu9PdQE4N8Fs26GSTrfxmTnvIDZSG5GvndQXoGgg9wA4pXXmb4Sd6qYhstIKzR4dX8Csctc5+H8oOd82du6P3jnPUw==' \
--data-urlencode 'card_encoding_version=2021-01-22'
Response
{
    "txn_uuid": "euluXfu9vGheGu4uX",
    "txn_id": "merchant_success-JP163552819-1",
    "status": "PENDING_VBV",
    "payment": {
        "authentication": {
            "url": "https://sandbox.juspay.in/v2/pay/start/merchant_success/euluXfu9vGheGu4uX",
            "method": "GET"
        }
    },
    "order_id": "JP1635528189",
    "offer_details": {
        "offers": []
    }
}
{
    "txn_uuid": "eulkbnyke823aRtyTpJ",
    "txn_id": "merchant_success-JP1635844655-1",
    "status": "PENDING_VBV",
    "payment": {
        "authentication": {
            "url": "https://sandbox.juspay.in/v2/pay/start/merchant_success/eulkbnyke823aRtyTpJ",
            "method": "GET"
        }
    },
    "order_id": "JP1635844655",
    "offer_details": {
        "offers": []
    }
}

You may use the below public key for testing in sandbox environment

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAizgY4XSKoSmDoSK5g5MaJS9hZvX5C6rgSYQui9rbdBw+WZq2pRSV6MDMJQFTb9grXx3Ztj1wt1ESN5VAA5Gff2EO77ffiUtX716dYNq7NfOM3y8ssQ3Kh02Ow1xnlb9vc3gRfG+LpblCEa+vE+2foZa1/AhbRuZkvferOjB3YwacUVc0y25gO9HIL9iGd8aCl2cVhvFg3NOfJRQK3yhv1mEar2k3AqGDj95Vw/stWytYFLDFzwU3xYlHxb3vNLunbMlfxCqluveOBh2huGEhb0QNT4pSBK2UVaCZmukjcTXKD0c97brip2ZOHLo50V+njxn46mq6gJfE7RKFjPd5/QIDAQAB
-----END PUBLIC KEY-----

For Production use the below Public Key.

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzHHLFnOqJ2LjHcAI1WvF6mpNv2zeokY0DbX46W/P4Rc6AVBg5CUcLPYjLed32qtQaHK6PhPsTwtTN9QLczhN6X9mp+1GK5Yxm/1DOC2PsvSkF3ZacSFYx1KHDVRjG3dPPj+fe3EBXkktOG/yVRbo0LlIaVk+6mEfI9Tn0+9SBJ+1y7y4EBGc+Wd/A5tN5dKJrzsuoQYuI9tKEtAIGsiHp93vYIKr2bDTV2Kl+iqzcQAJIqOOxVTahDGv9qDurSrm6wrs3XCoeCSWGiLB/MKqYdPzgYD2uctPkGAxmRCKshMXlIveRfskMTa562K72d5ZKsc1ehkEnQ8M8yzQ4f4QMQIDAQAB
-----END PUBLIC KEY-----