Some of our API endpoints require that you generate auth data per call.
AuthData is a combination of your payment’s sensitive data mainly: PAN, PIN, Expiry Date, and CVV2.
The BouncyCastle library is required for this, hence the need to download the appropriate BouncyCastle library for your platform.
You will also be provided with a public key exponent as well as a modulus.
Sample implementations exist for PHP and NodeJS on Github
Below is a sample code showing how to generate Auth data
Please contact [email protected] for more information.
String authDataVersion = "1";
String pan = "5060990580000217499"; // Payment Card
String expiryDate = "5003"; //Card Expiry date: April (04), 2020 (20) - YYMM
String cvv2 = "111"; // Card CVV2
String pin = "1111"; // Card pin
String authData = getAuthData(authDataVersion, pan, pin, expiryDate, cvv2);
System.out.println("AuthData : " + authData);
public static String getAuthData(String version, String pan, String pin, String expiryDate, String cvv2) throws Exception {
String authData = "";
String authDataCipher = version + "Z" + pan + "Z" + pin + "Z" + expiryDate + "Z" + cvv2;
// The Modulus and Public Exponent will be supplied by Interswitch. please ask for one
String modulus = "XXXXXXX";
String publicExponent = "XXXXXXX";
Security.addProvider(new BouncyCastleProvider());
RSAPublicKeySpec publicKeyspec = new RSAPublicKeySpec(new BigInteger(modulus, 16), new BigInteger(publicExponent, 16));
KeyFactory factory = KeyFactory.getInstance("RSA"); //, "JHBCI");
PublicKey publicKey = factory.generatePublic(publicKeyspec);
Cipher encryptCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC");
encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] authDataBytes = encryptCipher.doFinal(authDataCipher.getBytes("UTF8"));
authData = Base64.getEncoder().encodeToString(authDataBytes).replaceAll("\\r|\\n", "");
return authData;
}
public static String GetAuthData(string pan, string pin, string expiryDate, string cvv2, string modulus = null, string pubExpo = null)
{
if (pan != null)
{
pan = pan.Trim();
}
else
{
pan = "";
}
if (pan != null)
{
pan = pan.Trim();
}
else
{
pan = "";
}
if (cvv2 != null)
{
cvv2 = cvv2.Trim();
}
else
{
cvv2 = "";
}
if (expiryDate != null)
{
expiryDate = expiryDate.Trim();
}
else
{
expiryDate = "";
}
if (modulus != null)
publicKeyModulus = modulus;
if (pubExpo != null)
publicKeyExponent = pubExpo;
String authData = String.Format("1Z{0}Z{1}Z{2}Z{3}", pan, pin, expiryDate, cvv2);
string result = RsaEncryptWithPrivate(authData);
return result;
}
public static string RsaEncryptWithPrivate(string clearText)
{
BigInteger Mod = new BigInteger(publicKeyModulus, 16);
//static BigInteger Mod = new BigInteger(Encoding.UTF8.GetBytes(modulus));
BigInteger PubExp = new BigInteger(publicKeyExponent, 16);
var bytesToEncrypt = Encoding.UTF8.GetBytes(clearText);
RsaKeyParameters pubParameters = new RsaKeyParameters(false, Mod, PubExp);
Pkcs1Encoding encryptEngine = new Pkcs1Encoding(new RsaEngine());
encryptEngine.Init(true, pubParameters);
var encrypted = Convert.ToBase64String(encryptEngine.ProcessBlock(bytesToEncrypt, 0, bytesToEncrypt.Length));
return encrypted;
}