I'm integrating CC avenue in Ionic4 app with Node JS as my backend. Node JS API is whitelisted with CC avenue as this is the first most step in the integration of CC Avenue. I've methods for fetching the RSA key in the API. I'm not able to figure out how to post the encrypted params and open it in the New browser window with Redirect and Cancel URLs.
initPayment() {
this.authService.initPayment().then(
res => {
this.paymentParams = new PaymentParams();
this.paymentParams.orderId = JSON.parse(res).order_id;
this.paymentParams.amount = JSON.parse(res).amount;
this.paymentParams.currency = JSON.parse(res).currency;
this.paymentParams.merchantId = JSON.parse(res).merchant_id;
this.paymentParams.accessCode = JSON.parse(res).access_code;
this.paymentParams.cancelUrl = JSON.parse(res).redirect_url;
this.paymentParams.redirectUrl = JSON.parse(res).cancel_url;
this.paymentParams.transUrl = JSON.parse(res).trans_url;
this.paymentParams.rsaKeyURL = JSON.parse(res).rsa_key_uRL;
alert(JSON.stringify(this.paymentParams));
this.getRSA(this.paymentParams.orderId); // Gets the RSA key from CC Avenue
const payLink = this.inappBrowser.create(`${this.paymentParams.transUrl}`); // Here I want toadd the encryption for posting into Webview
},
err => {
alert(JSON.parse(err));
}
);
}
Below is the RSA utility provided by CC avenue written in Java. I'm trying to get the similar encryption using typescript in Ionic4.
public class RSAUtility {
public static String encrypt(String plainText, String key){
try{
PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decode(key, Base64.DEFAULT)));
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
return Base64.encodeToString(cipher.doFinal(plainText.getBytes("UTF-8")),Base64.DEFAULT);
}catch (Exception e) {
e.printStackTrace();
}
return null;
}
}