CZT
2023-08-07 7c8d42e0ff3e8d0be0521a4867dc4e1827c1f3b2
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
package com.fzzy.api.utils;
 
 
import cn.lxem.scde.SM2Crypto;
import sun.misc.BASE64Encoder;
 
import javax.imageio.ImageIO;
 
import java.awt.image.BufferedImage;
import java.io.*;
 
@SuppressWarnings("restriction")
public class SM2Utils{
 
 
    public static  String encrypt(String publicKeyHex,String data){
        return  SM2Crypto.encrypt(publicKeyHex,data,2);
    }
 
    public static void main(String[] args) throws Exception {
 
//        String p = SM2Crypto.encrypt("042DBA45E7B03394F603CADAFCDDEC854D3E01A4E9C52CD799B85B1A14BDB970137AE58BA553D79F058604DC1CD4B77DE5408BA3308E767584100C2B663510C819","LSJ12345678@",2);
//        System.out.println("加密:"+p);
 
 
//        Api1101 api1101 = new Api1101();
//        api1101.setKqdm("11111");
//        api1101.setZcrq(new Date());
//        String js = JSON.toJSONString(api1101);
//        System.out.println("json:"+js);
 
 
        //将图片文件转化为字节数组字符串,并对其进行Base64编码处理
        InputStream inputStream = null;
        byte[] buffer = null;
        //读取图片字节数组
        try {
            inputStream = new FileInputStream("C:\\Users\\75787\\Desktop\\image\\qiche.jpg");
            int count = 0;
            while (count == 0) {
                count = inputStream.available();
            }
            buffer = new byte[count];
            inputStream.read(buffer);
        } catch (IOException e) {
            //log.error(e.getMessage(),e);
        } finally {
            if (inputStream != null) {
                try {
                    // 关闭inputStream流
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
//        // 对字节数组Base64编码
//        return new BASE64Encoder().encode(buffer);
        System.out.println(new BASE64Encoder().encodeBuffer(buffer));
        System.out.println("-------------------------------------------------------------------------------------------------------------");
        BASE64Encoder encoder = new sun.misc.BASE64Encoder();
        File f = new File("C:\\Users\\75787\\Desktop\\image\\qiche.jpg");
        BufferedImage bi;
        try {
            bi = ImageIO.read(f);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ImageIO.write(bi, "jpg", baos);
            byte[] bytes = baos.toByteArray();
 
            System.out.println(encoder.encodeBuffer(bytes).trim());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
}