---
updatedAt: 2025-11-11T00:09:25.000Z
agentTools:
  projectIndex: https://docs.interswitchgroup.com/v1.1/llms.txt
---

# How to Generate Auth Data

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.

To generate auth data in `Java` and `C#`, you'll need the **BouncyCastle** [library](https://tomee.apache.org/bouncy-castle.html), so please download the appropriate version for your platform. Additionally, you'll be provided with a **public key** exponent and a **modulus**.

Sample implementations exist for [PHP](https://github.com/techquest/isw-payment-php) and [NodeJS](https://github.com/techquest/isw-payment-node) on GitHub.

> 📘 Below is a sample code showing how to generate Auth data
>
> Please contact <ipg@interswitchgroup.com> for more information.

```java
String authDataVersion = "1";
String pan = "5060990580000217499";        // Payment Card
String expiryDate = "2004";                //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;
}
```
```csharp
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;
}
```