· 4 years ago · Apr 12, 2021, 07:32 AM
1package id.co.sofcograha.gajiidapi;
2import java.math.BigInteger;
3import java.security.MessageDigest;
4import java.security.NoSuchAlgorithmException;
5import java.util.HashMap;
6import java.util.Map;
7
8import com.fasterxml.jackson.core.JsonProcessingException;
9import com.fasterxml.jackson.databind.ObjectMapper;
10
11public class TokenDarwinbox {
12
13 private static final String _SECRET_KEY = "720929cf9f4b815f4f8c8b3e28d1a4ee";
14 private static final String _UID = "TTEO315S99ERCL";
15 private static final String _ADMIN_EMAIL_ID = "integrations1@yopmail.com";
16 private static final String _DSK_ACTIVE_EMPLOYEE = "9b5288ebc3f068410d8259aaca053f10aabd473cd2948585d72b38d40eb0cc575c5574b835509662e60aa8f4097ad27117ece7e957e1216663729fd39735b9b1";
17 private static final String _DSK_INACTIVE_EMPLOYEE = "c636b99294f2b58051aaf17cc7f1b640c02b35bad0d1d75f426ceb4ad5a87ee440a4c903acf06a6ff9684183718104039b7f4c2eb3aa1bd41065d49996b61c5b";
18
19 public static String hash(String input)
20 {
21 try {
22 // getInstance() method is called with algorithm SHA-512
23 MessageDigest md = MessageDigest.getInstance("SHA-512");
24
25 // digest() method is called
26 // to calculate message digest of the input string
27 // returned as array of byte
28 byte[] messageDigest = md.digest(input.getBytes());
29
30 // Convert byte array into signum representation
31 BigInteger no = new BigInteger(1, messageDigest);
32
33 // Convert message digest into hex value
34 String hashtext = no.toString(16);
35
36 // Add preceding 0s to make it 32 bit
37 while (hashtext.length() < 32) {
38 hashtext = "0" + hashtext;
39 }
40
41 // return the HashText
42 return hashtext;
43 }
44
45 // For specifying wrong message digest algorithms
46 catch (NoSuchAlgorithmException e) {
47 throw new RuntimeException(e);
48 }
49 }
50 public static long getTimeStamp()
51 {
52// Calendar calendar = Calendar.getInstance();
53// //Returns current time in millis
54// long timeMilli2 = calendar.getTimeInMillis();
55 return System.currentTimeMillis() / 1000;
56 }
57
58 // Driver code
59 public static void main(String args[]) throws NoSuchAlgorithmException
60 {
61 long timestamp = getTimeStamp();
62 String s1 = _ADMIN_EMAIL_ID + _SECRET_KEY + timestamp;
63 System.out.println("before-hash: " + s1);
64 String hash = hash(s1);
65 System.out.println("after-hash: " + hash);
66 System.out.println("copy starting from down here \n");
67 Map<String, Object> paramsActiveEmployee = new HashMap<>();
68 paramsActiveEmployee.put("email", _ADMIN_EMAIL_ID);
69 paramsActiveEmployee.put("timestamp", timestamp);
70// params.put("secretkey", _SECRET_KEY);
71 paramsActiveEmployee.put("hash", hash);
72 paramsActiveEmployee.put("Uid", _UID);
73 paramsActiveEmployee.put("datasetKey", _DSK_ACTIVE_EMPLOYEE);
74// params.put("last_modified", "07-04-2021 00:00:00");
75
76 ObjectMapper mapper = new ObjectMapper();
77 String jsonFromMap = "";
78 try {
79 jsonFromMap = mapper.writeValueAsString(paramsActiveEmployee);
80 } catch (JsonProcessingException e) {
81 e.printStackTrace();
82 }
83
84 System.out.println("payload-active-employee");
85 System.out.println(jsonFromMap);
86
87 Map<String, Object> paramsInactiveEmployee = new HashMap<>();
88 paramsInactiveEmployee.put("email", _ADMIN_EMAIL_ID);
89 paramsInactiveEmployee.put("timestamp", timestamp);
90 paramsInactiveEmployee.put("hash", hash);
91 paramsInactiveEmployee.put("Uid", _UID);
92 paramsInactiveEmployee.put("datasetKey", _DSK_INACTIVE_EMPLOYEE);
93
94 jsonFromMap = "";
95 try {
96 jsonFromMap = mapper.writeValueAsString(paramsActiveEmployee);
97 } catch (JsonProcessingException e) {
98 e.printStackTrace();
99 }
100
101 System.out.println("payload-inactive-employee");
102 System.out.println(jsonFromMap);
103 }
104}
105