|
@@ -1,55 +1,38 @@
|
|
|
package com.iamberry.rst.utils;
|
|
|
+import com.auth0.jwt.internal.org.apache.commons.codec.binary.Base64;
|
|
|
+import com.auth0.jwt.internal.org.apache.commons.codec.binary.StringUtils;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
|
+
|
|
|
+
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
+import java.security.Key;
|
|
|
|
|
|
-import javax.print.Doc;
|
|
|
-import javax.print.DocFlavor;
|
|
|
-import javax.print.DocPrintJob;
|
|
|
-import javax.print.PrintService;
|
|
|
-import javax.print.PrintServiceLookup;
|
|
|
-import javax.print.ServiceUI;
|
|
|
-import javax.print.SimpleDoc;
|
|
|
-import javax.print.attribute.DocAttributeSet;
|
|
|
-import javax.print.attribute.HashDocAttributeSet;
|
|
|
-import javax.print.attribute.HashPrintRequestAttributeSet;
|
|
|
-import javax.swing.JFileChooser;
|
|
|
+import javax.crypto.Cipher;
|
|
|
+import javax.crypto.spec.SecretKeySpec;
|
|
|
|
|
|
|
|
|
public class test {
|
|
|
+ private static final String AES = "AES";
|
|
|
+
|
|
|
+ public static String decrypt(String encryptedData, String secretKey) throws Exception {
|
|
|
+ Key key = new SecretKeySpec(secretKey.getBytes(), AES);
|
|
|
+ Cipher c = Cipher.getInstance(AES);
|
|
|
+ c.init(2, key);
|
|
|
+ byte[] decodedValue = Base64.decodeBase64(encryptedData);
|
|
|
+ byte[] decValue = c.doFinal(decodedValue);
|
|
|
+ String decryptedValue = StringUtils.newStringUtf8(decValue);
|
|
|
+ return decryptedValue;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- //获取系统所有打印机
|
|
|
- PrintService[] services = PrintServiceLookup.lookupPrintServices(null,null);
|
|
|
- for (int i = 0;i<=services.length;i++){
|
|
|
- System.out.println(services[i].getName());
|
|
|
- }
|
|
|
- JFileChooser fileChooser = new JFileChooser(); //创建打印作业
|
|
|
- int state = fileChooser.showOpenDialog(null);
|
|
|
- if(state == fileChooser.APPROVE_OPTION){
|
|
|
- File file = new File("D:/123.jpg"); //获取选择的文件
|
|
|
- //构建打印请求属性集
|
|
|
- HashPrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
|
|
|
- //设置打印格式,因为未确定类型,所以选择autosense
|
|
|
- DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
|
|
|
- //查找所有的可用的打印服务
|
|
|
- PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
|
|
|
- //定位默认的打印服务
|
|
|
- PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
|
|
|
- //显示打印对话框
|
|
|
- PrintService service = ServiceUI.printDialog(null, 200, 200, printService,
|
|
|
- defaultService, flavor, pras);
|
|
|
-
|
|
|
- if(service != null){
|
|
|
- try {
|
|
|
- DocPrintJob job = service.createPrintJob(); //创建打印作业
|
|
|
- FileInputStream fis = new FileInputStream(file); //构造待打印的文件流
|
|
|
- DocAttributeSet das = new HashDocAttributeSet();
|
|
|
- Doc doc = new SimpleDoc(fis, flavor, das);
|
|
|
- job.print(doc, pras);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
+ ConsumerRecord<String, String> record = new ConsumerRecord<String, String>("4", 1, 1, "data", "{\"data\":\"7uiBfrOFcdy/EDWxcT6SlZT7AORkrnWt533GP2oqstJT1zxbCQqLcNSyaITdfYZmhmZ8/vfzF9f8C5g7pKI8TvzaeeNu675pH3s5SP/5/bbL/U3eNahyWWQsMG1IhNtU66l6wd5Dwk5OTnoZmtRAliyN4Z9QwWjLU8DB11VW+EUGiD/1RodRhug3+ZLYgebFeJ/qT+1lbw86aX6QZNppgqByHL04wHsuQcOr6BVt1n0=\"}");
|
|
|
+ String appKey = "5kkyurvvtt58bbuxueee";//填APP KEY
|
|
|
+ String secretKey = "rhj6na6u3y6uhy6qrbb3944mg5uqqpbb";//APP SECRET
|
|
|
+ String data = decrypt(JSONObject.fromObject(record.value()).getString("data"),
|
|
|
+ secretKey.substring(8, 24));//解析后的真正数据
|
|
|
+System.out.println(data);
|
|
|
}
|
|
|
}
|