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