CCAvenue does not provide integration kit for Salesforce Apex language. They provide Asp.net, Java, NodeJS, iOS, Android, Windows.

How do we encrypt and decrypt data and make request for CCAvenue payment gateway?

1 Answer 1


After lots of struggle we managed to get encrypt and decrypt data in Salesforce Apex.

Here is Encryption:

This PLAIN_TEXT is your data collected from your apex form. Few values are required and lots of values are optional. Please read document provided by ccavenue.

String PLAIN_TEXT = 'tid=XXXX&merchant_id=XXXX&order_id=XXXX&amount=XX&currency=INR&redirect_url=XXXX&cancel_url=XXXX&language=EN&billing_name=XXXX&billing_address=XXXX&billing_city=XXXX&billing_state=XX&billing_zip=XXXX&billing_country=XXXX&billing_tel=XXXX&billing_email=XXXX&delivery_name=XXXX&delivery_address=XXXX&delivery_city=XXXX&delivery_state=XXXX&delivery_zip=XXXX&delivery_country=XXXX&delivery_tel=XXXX&merchant_param1=XXXX&merchant_param2=XXXX&merchant_param3=XXXX&merchant_param4=XXXX&merchant_param5=XXXX&promo_code=&customer_identifier=&';

//WORKING_KEY is key provided by CCAvenue when you register as Merchant.

Blob cryptoKey = Blob.valueOf('WORKING_KEY'); 
Blob hash = Crypto.generateDigest('MD5', cryptoKey );
Blob data = Blob.valueOf(PLAIN_TEXT);
Blob encryptedData = Crypto.encryptWithManagedIV('AES128', hash , data);
String encRequest = EncodingUtil.convertToHex(encryptedData ); 

/*Pass this encRequest with access_code to the https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction using visualforce FORM

**Here is Decryption:**

Blob cryptoKey = Blob.valueOf('WORKING_KEY');
Blob hash = Crypto.generateDigest('MD5', cryptoKey);
Blob data = EncodingUtil.convertFromHex('ENC_RESPONSE'); //Received from ccAvenue response
Blob decryptedText = Crypto.decryptWithManagedIV('AES128', hash, data);
String PLAIN_TEXT = decryptedText.toString();
  • Is it working? I used above code for encRequest, it is return 741 character encRequest, but I want only 256 character for encRequest. Is it Possible? Commented Jan 15 at 5:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .