1. Home
  2. Interswitch Security Headers
  3. Sample Code

Sample Code

// Timestamp

TimeZone lagosTimeZone = TimeZone.getTimeZone(“Africa/Lagos”);  Calendar calendar = Calendar.getInstance(lagosTimeZone);  long timestamp = calendar.getTimeInMillis() / 1000;

 

// Nonce 

UUID uuid = UUID.randomUUID();

String nonce = uuid.toString().replaceAll(“-“, “”);

 

// Signature Method 

String signatureMethod = “SHA512”;

 

// Signature 

String httpMethod = “POST”; // HTTP Method of the resource that is being called

String encodedResourceUrl = “RESOURCE_URL”;  // put the resource URL here

String clientId = “CLIENT_ID”;  // put your client Id here

String clientSecretKey = “CLIENT_SECRET_KEY”;  // put your client secret here

String signatureCipher = httpMethod + “&” + encodedResourceUrl + “&” + timestamp + “&” + nonce + “&” + clientId + “&” + clientSecretKey;

MessageDigest messageDigest = MessageDigest.getInstance(signatureMethod);

byte[] signatureBytes = messageDigest.digest(signatureCipher.getBytes());

String signature = new String(Base64.encodeBase64(signatureBytes));

 

// Setting HTTP Header values 

String resourceUrl = “https://sandbox.interswitchng.com/passport/oauth/token”;

HttpPost post = new HttpPost(resourceUrl);

post.setHeader(“TIMESTAMP”, timestamp);

post.setHeader(“NONCE”, nonce);

post.setHeader(“SIGNATURE_METHOD”, signatureMethod);

post.setHeader(“SIGNATURE”, signature)

Was this article helpful to you? Yes No

How can we help?