question

abhimalamkar avatar image
abhimalamkar asked Frank Faustino Deactivated edited

Getting cardEncrypted from webpay

Hello,
I have been trying to get the cardEncrypted in android java

public static PublicKey getPublicKey(final BigInteger modulus, final BigInteger exponent) {
  try {
    final KeyFactory factory = KeyFactory.getInstance("RSA");
    final PublicKey publicKey = factory.generatePublic(new RSAPublicKeySpec(modulus, exponent));
    return publicKey;
  } catch (GeneralSecurityException e) {
    return null;
  }
}


public static String encryptPAN(final String prefix, final String pan, PublicKey publicKey) {
  byte[] input = String.format("%s%s", prefix, pan).getBytes();


  try {
    Cipher cipher = Cipher.getInstance("RSA/None/OAEPWithSHA1AndMGF1Padding");
    cipher.init(Cipher.ENCRYPT_MODE, publicKey, new SecureRandom());
    byte[] cipherText = cipher.doFinal(input);
    return Base64.encodeToString(cipherText, Base64.DEFAULT);
  } catch (GeneralSecurityException ignore) {
    return null;
  }
}

here is the code

I am getting

{
  "paymentId": "6KMQGW15R5N44",
  "result": "DECLINED",
  "failureMessage": "RE0528 - EncrptBlock is invalid|"
}

Payments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Frank Faustino avatar image
Frank Faustino Deactivated answered Frank Faustino Deactivated edited
Please take a look at our Java example implementation from this repo.
https://github.com/frankfaustino/DeveloperPayAPI/blob/master/java/src/com/company/Main.java
Let me know if you can get it working. Make sure project SDK, language level and JRE are set to Java 8.

Also, since you're developing an Android app, you can use the Clover Android SDK. Here's our documentation on it: https://docs.clover.com/clover-platform/docs/using-payment-connector
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community