Skip to content

Commit

Permalink
update some bug pem file and time bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rmtomal00 committed May 7, 2024
1 parent 7350cab commit 520eb63
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:17-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ./target/Nagad-Payment-0.0.1-SNAPSHOT.jar Nagad_payment.jar
COPY ./target/Nagad-Payment-0.0.2-SNAPSHOT.jar Nagad_payment.jar
ENTRYPOINT ["java","-jar", "Nagad_payment.jar"]
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.tomal</groupId>
<artifactId>Nagad-Payment</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
<name>Nagad-Payment</name>
<description>Nagad project for Spring Boot</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
public class CryptoCommon {


//InputStream inputStream = getClass().getResourceAsStream("/marchent_private.pem");
//InputStream publicKey = getClass().getResourceAsStream("/marchent_public.pem");

public byte[] sign(PrivateKey merchantPrivateKey, byte[] bytes) {
Object var4 = null;

Expand Down Expand Up @@ -67,7 +64,7 @@ public PublicKey getPublic() throws Exception {
InputStream inputStream = resource.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String content = reader.readLine();
System.out.println(content);
//System.out.println(content);

content = content.replaceAll("\\s", "");

Expand All @@ -82,7 +79,7 @@ public PrivateKey getPrivate() throws Exception {
InputStream inputStream = resource.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String content = reader.readLine();
System.out.println(content);
//System.out.println(content);

content = content.replaceAll("\\s", "");

Expand Down
22 changes: 14 additions & 8 deletions src/main/java/com/tomal/Nagad/Payment/services/NagadServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Base64;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -44,9 +47,11 @@ public class NagadServices {
public String create(Map<String, Object> data, String ipAddress) throws Throwable {
byte[] KPG_DefaultSeed = ("nagad-dfs-service-ltd" + System.currentTimeMillis() + "").getBytes();;
String random = common.generateRandomString(20, KPG_DefaultSeed);
Date date = new Date();
DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
String datetime = format.format(date);
ZoneId dhakaZone = ZoneId.of("Asia/Dhaka");
ZonedDateTime currentDhakaTime = ZonedDateTime.now(dhakaZone);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
//DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
String datetime = formatter.format(currentDhakaTime);
Long orderId = System.currentTimeMillis();
Map<String, Object> rawData = new HashMap<>();
rawData.put("merchantId", marchentId);
Expand Down Expand Up @@ -85,7 +90,7 @@ public String create(Map<String, Object> data, String ipAddress) throws Throwabl

Response response = client.newCall(request).execute();
String responsedata = response.body().string();
//System.out.println(responsedata);

ApiInitializeModel apiData = new Gson().fromJson(responsedata, ApiInitializeModel.class);
byte[] dataDecode = common.decrypt(common.getPrivate(), decoder.decode(apiData.getSensitiveData()));
String responseSensitiveData = new String(dataDecode, StandardCharsets.UTF_8);
Expand All @@ -103,15 +108,16 @@ public String create(Map<String, Object> data, String ipAddress) throws Throwabl
//System.out.println(mapper.writeValueAsString(data));

rawDataToBeEncrypted = mapper.writeValueAsString(data);
rawEncryptedBytes = common.encrypt(common.getPublic(), rawDataToBeEncrypted.getBytes("UTF-8"));
rawSignatureBytes = common.sign(common.getPrivate(), rawDataToBeEncrypted.getBytes("UTF-8"));
System.out.println(rawDataToBeEncrypted);
rawEncryptedBytes = common.encrypt(common.getPublic(), rawDataToBeEncrypted.getBytes(StandardCharsets.UTF_8));
rawSignatureBytes = common.sign(common.getPrivate(), rawDataToBeEncrypted.getBytes(StandardCharsets.UTF_8));
sensitiveData = encoder.encodeToString(rawEncryptedBytes);
signature = encoder.encodeToString(rawSignatureBytes);

System.out.println("work ");
Map<String, Object> productInfo = new HashMap<>();
productInfo.put("productName", "T-Shirt");
productInfo.put("quantity", "1");
String pro = mapper.writeValueAsString(productInfo);
//String pro = mapper.writeValueAsString(productInfo);
//System.out.println(pro);

JSONObject object = new JSONObject();
Expand Down

0 comments on commit 520eb63

Please sign in to comment.