1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| import java.util.Base64; import java.util.UUID; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import net.sf.json.JSONObject;
public class CpdailyExtension { private static final String MODE_ALGORITHM = "DES"; private static final String NAME = "DES/CBC/PKCS5Padding"; private static final String CHARSET = "UTF-8"; private static final String TEXT = "abcde"; private static final String KEY = "ST83=@XV"; private static byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8 };
public static String Base64Encrypt(byte[] bytes) { return Base64.getEncoder().encodeToString(bytes); }
public static byte[] Base64Decrypt(byte[] bytes) { return Base64.getDecoder().decode(bytes); }
public static String DESEncrypt(String text, String key, String charset) throws Exception { SecretKeySpec sks = new SecretKeySpec(key.getBytes(charset), MODE_ALGORITHM); IvParameterSpec ivPS = new IvParameterSpec(iv); Cipher cipher = Cipher.getInstance(NAME); cipher.init(Cipher.ENCRYPT_MODE, sks, ivPS); byte[] doFinal = cipher.doFinal(text.getBytes(charset)); return Base64Encrypt(doFinal);
}
public static String DESDecrypt(byte[] text, String key, String charset) throws Exception { text = Base64Decrypt(text); SecretKeySpec sks = new SecretKeySpec(key.getBytes(charset), MODE_ALGORITHM); IvParameterSpec ivPS = new IvParameterSpec(iv); Cipher cipher = Cipher.getInstance(NAME); cipher.init(Cipher.DECRYPT_MODE, sks, ivPS); return new String(cipher.doFinal(text)); }
public static String generateCpdailyExtension(String id) { JSONObject object = new JSONObject(); object.put("systemName", "android"); object.put("systemVersion", "11"); object.put("model", "MI 11"); object.put("deviceId", UUID.randomUUID().toString()); object.put("appVersion", "8.1.11"); object.put("lon", 116.32284422133253); object.put("lat", 40.00301874717021); object.put("userId", id); try { return DESEncrypt(object.toString(), KEY, CHARSET); } catch (Exception e) { e.printStackTrace(); return null; } } public static void main(String[] args) { System.out.println(generateCpdailyExtension("5201314")); } }
|