· 8 years ago · Jan 26, 2018, 02:24 PM
1//*******************************************************************
2// Dear CompileJava users,
3//
4// CompileJava has been operating since 2013 completely free. If you
5// find this site useful, or would otherwise like to contribute, then
6// please consider a donation (link in 'More Info' tab) to support
7// development of the new CompileJava website (stay tuned!).
8//
9// Most sincerely, Z.
10//*******************************************************************
11
12import java.lang.Math; // headers MUST be above the first class
13import java.lang.reflect.Array;
14import java.util.Arrays;
15import javax.crypto.Cipher;
16import javax.crypto.SecretKey;
17import javax.crypto.spec.IvParameterSpec;
18import javax.crypto.spec.SecretKeySpec;
19import java.util.Base64;
20
21// one class needs to have a main() method
22public class HelloWorld
23{
24 // arguments are passed using the text field below this editor
25 public static void main(String[] args)
26 {
27 // GET PRIVATE KEY
28 String key = "C38FB23A402222A0C17D34A92F971D1F";
29 SecretKeySpec secretKey = null;
30 byte[] keyBytes = new byte[32];
31 Arrays.fill(keyBytes, (byte) 0);
32 try {
33 byte[] passwordBytes = key.getBytes("UTF-8");
34 System.arraycopy(passwordBytes, 0, keyBytes, 0, passwordBytes.length < keyBytes.length ? passwordBytes.length : keyBytes.length);
35 System.out.println("Special key = " + keyBytes);
36 secretKey = new SecretKeySpec(keyBytes, "AES");
37 } catch (Exception e) {
38 System.out.println(e.getMessage());
39 }
40 String stringToEncode = "platform=android&applicationKey=1&applicationUserId=1&sdkVersion=6.6.8.1&appVer=1&osVer=8&devMake=1&devModel=1";
41 String str;
42 try {
43 SecretKeySpec skeySpec = secretKey;
44 System.out.println(skeySpec.getEncoded().length);
45 byte[] clearText = stringToEncode.getBytes("UTF8");
46 byte[] iv = new byte[16];
47 Arrays.fill(iv, (byte) 0);
48 IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
49 Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
50 cipher.init(1, skeySpec, ivParameterSpec);
51 str = Base64.getEncoder().encodeToString(cipher.doFinal(clearText)).replaceAll(System.getProperty("line.separator"), "");
52 System.out.println("result = " + str);
53 } catch (Exception e) {
54 e.printStackTrace();
55 str = "";
56 }
57 }
58}