Android Client-Side Encryption SDK

Android CSE SDK logo

The Android Client Side Encryption (CSE) SDK encrypts card data on the customer's Android device. You build your own card form in your app, the SDK encrypts what the customer enters, and your server sends the encrypted string to Buckaroo. The card data never reaches your server unencrypted, and only Buckaroo can decrypt it.

Building for another platform? Use the iOS Client Side Encryption SDK for iOS apps or the JS Client Side Encryption SDK for websites.


Download the SDK


How it works

  1. Show a card form.
    Your app asks for the card number, expiry date, security code and cardholder name.
  2. Validate and encrypt.
    The SDK checks the input and turns it into one encrypted string, on the device.
  3. Send the string to your server.
    Your app sends the encrypted string to your server, not the card data.
  4. Start the payment.
    Your server sends the string to Buckaroo in a PayEncrypted or AuthorizeEncrypted request.

Supported payment methods

  • All credit cards
  • Bancontact

Requirements

RequirementDetails
AndroidAPI level 15 or higher
LanguageWritten in Java. Also usable from Kotlin
DependenciesNone

Add the SDK

The SDK is an Android library module. Download it and add it to your project as a module.

All functions are static methods on the CSE class:

import nl.buckaroo.cse.CSE;
import nl.buckaroo.cse.CardBrand;

Validate the input

Use the validation methods to check each field before you encrypt. They return true or false.

MethodChecks
validateCardNumber(cardNumber, cardBrand)10 to 19 digits and a valid check digit. With a card brand, also the number format for that card
validateCvc(cvc, cardBrand)3 or 4 digits, or empty. With a card brand, the length for that card
validateYear(year)2 or 4 digits
validateMonth(month)A number from 1 to 12
validateCardholderName(name)Not empty

cardBrand is one of CardBrand.Visa, CardBrand.Mastercard, CardBrand.Amex, CardBrand.Maestro or CardBrand.Bancontact. Pass null when you do not know the brand.

predictCardBrand(cardNumberBeginning) gives the likely brand from the first digits of the card number, so you can show the card logo while the customer types. It returns CardBrand.Unknown when it cannot tell yet.

  • Remove spaces and other non-digit characters from the card number, month and security code before you validate. The SDK expects digits only
  • Pass null, not CardBrand.Unknown, to the validation methods when the brand is unknown. With CardBrand.Unknown, validateCardNumber always returns false
  • validateYear and validateMonth check the format, not whether the card has expired
  • Maestro and Bancontact cards have no security code. Pass an empty string for those

Encrypt the card data

CSE.encrypt takes the five card values and returns the encrypted string.

String encryptedCardData = CSE.encrypt(
    "5386860000000000", // card number
    "2030",             // expiry year
    "12",               // expiry month
    "123",              // security code, or "" for Maestro and Bancontact
    "A DE GROOT"        // cardholder name
);

if (encryptedCardData != null) {
    // send encryptedCardData to your server
}

If the encryption fails, the method returns null.


Encrypt a security code

CSE.encrypt with one argument encrypts only the security code. Use it for requests that take an EncryptedSecurityCode, such as a payment with a stored card where the customer only enters the security code again.

String encryptedSecurityCode = CSE.encrypt("123");

Full example

Validate the input, then encrypt it:

import nl.buckaroo.cse.CSE;
import nl.buckaroo.cse.CardBrand;

public String encryptCard(String cardNumberInput, String month, String year, String cvc, String cardholder) {
    String cardNumber = cardNumberInput.replaceAll("\\D", "");

    CardBrand predicted = CSE.predictCardBrand(cardNumber);
    CardBrand brand = predicted == CardBrand.Unknown ? null : predicted;

    boolean valid =
        CSE.validateCardNumber(cardNumber, brand)
            && CSE.validateMonth(month)
            && CSE.validateYear(year)
            && CSE.validateCvc(cvc, brand)
            && CSE.validateCardholderName(cardholder);

    if (!valid) {
        return null; // show an error in your form
    }

    // Send the result to your own server, never the card data itself
    return CSE.encrypt(cardNumber, year, month, cvc, cardholder);
}

Start the payment on your server

Send the encrypted string to Buckaroo in the EncryptedCardData parameter of a PayEncrypted or AuthorizeEncrypted request. See Credit cards and Bancontact for the request details.

From there the payment continues as if the customer had entered the card on the Buckaroo payment page. The response is either a redirect URL for 3D Secure authentication, or the status of the transaction.

The Buckaroo SDKs have a ready-made call for this request. See the PHP SDK, Node SDK and Python SDK.


Go live

Client Side Encryption has to be enabled for your account before you can use it for live payments.

  1. Test the full flow in the test environment. See Test transactions for test cards
  2. Complete the PCI SAQ-A self-assessment form and send it to Buckaroo
  3. Buckaroo enables Client Side Encryption for your live payments


Did this page help you?