· 5 years ago · Jul 01, 2020, 06:44 PM
1public class HelloWorld{
2
3 public static void main(String []args){
4 String time = String.valueOf(System.currentTimeMillis()/1000);
5 int key = 64;
6 String pkey = "555026eac0a4d140916813b6e0fa18acf72fde978f212ffd61207def77e26065";
7 int overheadLength = 48;
8 byte[] pkeyArray = new byte[pkey.length() / 2];
9 for (int i = 0; i < pkeyArray.length; i++) {
10 int index = i * 2;
11 int j = Integer.parseInt(pkey.substring(index, index + 2), 16);
12 pkeyArray[i] = (byte) j;
13 }
14
15 byte [] y = new byte[password.length()+36+16+overheadLength];
16
17 int f = 0;
18 y[f] = 1;
19 y[f += 1] = (byte)key;
20 f += 1;
21
22 KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
23 keyGenerator.init(256);
24
25 // Generate Key
26 SecretKey secretKey = keyGenerator.generateKey();
27 byte[] IV = new byte[12];
28
29 Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
30 SecretKeySpec keySpec = new SecretKeySpec(secretKey.getEncoded(), "AES");
31 GCMParameterSpec gcmParameterSpec = new GCMParameterSpec(128, IV);
32 cipher.init(Cipher.ENCRYPT_MODE, keySpec, gcmParameterSpec);
33 cipher.updateAAD(time.getBytes());
34
35 byte [] sealed = SealedBoxUtility.crypto_box_seal(secretKey.getEncoded(),pkeyArray);
36 byte[] cipherText = cipher.doFinal(password.getBytes());
37 y[f] = (byte) (255 & sealed.length);
38 y[f + 1] = (byte) (sealed.length >> 8 & 255);
39 f += 2;
40 for(int j=f;j<f+sealed.length;j++){
41 y[j] = sealed[j-f];
42 }
43 f += 32;
44 f += overheadLength;
45
46 byte [] c = Arrays.copyOfRange(cipherText,cipherText.length -16,cipherText.length);
47 byte [] h = Arrays.copyOfRange(cipherText,0,cipherText.length - 16);
48
49 for(int j=f;j<f+c.length;j++){
50 y[j] = c[j-f];
51 }
52 f += 16;
53 for(int j=f;j<f+h.length;j++){
54 y[j] = h[j-f];
55 }
56 String encPassword = Base64.getEncoder().encodeToString(y);
57 return "#PWD_INSTAGRAM_BROWSER:10:"+time+":"+encPassword;
58 }
59}