12 changed files with 167 additions and 58 deletions
-
1.classpath
-
12src/main/java/com/test/world/DTO/RefundRequest.java
-
93src/main/java/com/test/world/controller/PaymentController.java
-
20src/main/java/com/test/world/service/PaymentGatewayService.java
-
92src/main/java/com/test/world/service/PaymentGatewayServiceImpl.java
-
5src/main/java/com/test/world/service/WorldService.java
-
2target/classes/META-INF/maven/com.test/world/pom.properties
-
BINtarget/classes/com/test/world/DTO/RefundRequest.class
-
BINtarget/classes/com/test/world/controller/PaymentController.class
-
BINtarget/classes/com/test/world/service/PaymentGatewayService.class
-
BINtarget/classes/com/test/world/service/PaymentGatewayServiceImpl.class
-
BINtarget/classes/com/test/world/service/WorldService.class
@ -0,0 +1,12 @@ |
|||||
|
package com.test.world.DTO; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
|
||||
|
public class RefundRequest { |
||||
|
|
||||
|
private HashMap<String, String> merchant; |
||||
|
private HashMap<String,String> transaction; |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
package com.test.world.service; |
||||
|
|
||||
|
import java.io.UnsupportedEncodingException; |
||||
|
import java.security.InvalidAlgorithmParameterException; |
||||
|
import java.security.InvalidKeyException; |
||||
|
import java.security.NoSuchAlgorithmException; |
||||
|
|
||||
|
import javax.crypto.BadPaddingException; |
||||
|
import javax.crypto.IllegalBlockSizeException; |
||||
|
import javax.crypto.NoSuchPaddingException; |
||||
|
|
||||
|
public interface PaymentGatewayService { |
||||
|
|
||||
|
public String generateToken(String token)throws NoSuchAlgorithmException; |
||||
|
public String encryptHxRefund(String text, byte[] iv, byte[] key) throws Exception; |
||||
|
public String ToHexStrRefund(byte[] dataBuf); |
||||
|
public String decryptHxTRefund(String hxstrr, byte[] iv, byte[] key) throws Exception; |
||||
|
public byte[] FromHexStr (String hxStr); |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,92 @@ |
|||||
|
package com.test.world.service; |
||||
|
|
||||
|
import java.io.UnsupportedEncodingException; |
||||
|
import java.math.BigInteger; |
||||
|
import java.security.InvalidAlgorithmParameterException; |
||||
|
import java.security.InvalidKeyException; |
||||
|
import java.security.MessageDigest; |
||||
|
import java.security.NoSuchAlgorithmException; |
||||
|
|
||||
|
import javax.crypto.BadPaddingException; |
||||
|
import javax.crypto.Cipher; |
||||
|
import javax.crypto.IllegalBlockSizeException; |
||||
|
import javax.crypto.NoSuchPaddingException; |
||||
|
import javax.crypto.spec.IvParameterSpec; |
||||
|
import javax.crypto.spec.SecretKeySpec; |
||||
|
import org.apache.commons.codec.binary.Hex; |
||||
|
|
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
@Service |
||||
|
public class PaymentGatewayServiceImpl implements PaymentGatewayService { |
||||
|
|
||||
|
@Override |
||||
|
public String generateToken(String token) throws NoSuchAlgorithmException { |
||||
|
System.out.println("Token:-" + token); |
||||
|
MessageDigest md = MessageDigest.getInstance("SHA-512"); |
||||
|
md.update(token.getBytes()); |
||||
|
|
||||
|
byte[] bytes = md.digest(); |
||||
|
|
||||
|
BigInteger bigInt = new BigInteger(1, bytes); |
||||
|
String encryptedtoken = bigInt.toString(16); |
||||
|
|
||||
|
while (encryptedtoken.length() < 128) { |
||||
|
encryptedtoken = "0" + encryptedtoken; |
||||
|
} |
||||
|
; |
||||
|
System.out.println("Encryption :- " + encryptedtoken); |
||||
|
return encryptedtoken; |
||||
|
} |
||||
|
|
||||
|
//The process of encryption for refund API |
||||
|
@Override |
||||
|
public String encryptHxRefund(String text, byte[] iv, byte[] key) throws Exception { |
||||
|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); |
||||
|
SecretKeySpec keySpec = new SecretKeySpec(key, "AES"); |
||||
|
IvParameterSpec ivSpec = new IvParameterSpec(iv); |
||||
|
cipher.init(1, keySpec, ivSpec); |
||||
|
byte[] results = cipher.doFinal(text.getBytes("UTF-8")); |
||||
|
String hxencstr = ToHexStrRefund(results); |
||||
|
return hxencstr; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String ToHexStrRefund(byte[] dataBuf) { |
||||
|
String hxstr = null; |
||||
|
Hex hx = new Hex(); |
||||
|
hxstr = new String(hx.encode(dataBuf)); |
||||
|
return hxstr; |
||||
|
} |
||||
|
|
||||
|
//The process of decryption for refund API |
||||
|
@Override |
||||
|
public String decryptHxTRefund(String hxstrr, byte[] iv, byte[] key) throws Exception{ |
||||
|
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); |
||||
|
|
||||
|
SecretKeySpec keySpec = new SecretKeySpec(key, "AES"); |
||||
|
IvParameterSpec ivSpec = new IvParameterSpec(iv); |
||||
|
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec); |
||||
|
|
||||
|
byte[] decbytes = FromHexStr(hxstrr); |
||||
|
|
||||
|
byte[] results = cipher.doFinal(decbytes); |
||||
|
return new String(results, "UTF-8").trim(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public byte[] FromHexStr(String hxStr) { |
||||
|
byte[] charArray = hxStr.getBytes(); |
||||
|
byte[] bufstr = null; |
||||
|
Hex hxx = new Hex(); |
||||
|
|
||||
|
try { |
||||
|
bufstr = hxx.decode(charArray); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
|
||||
|
return bufstr; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -1,5 +0,0 @@ |
|||||
package com.test.world.service; |
|
||||
|
|
||||
public class WorldService { |
|
||||
|
|
||||
} |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue