利用gzip压缩字符串及处理流程

  1. 使用了hutool类库的Base64和zip工具类,用来压缩二维码中的长json字符串。
  2. 自定义工具类:
public final class QrGzipUtil {

    // 压缩
    public static String gzip(String toGzip) {
        return Base64.encode(ZipUtil.gzip(toGzip, CharsetUtil.CHARSET_UTF_8.name()));
    }

    // 解压
    public static String unGzip(String toUnGzip) {
        byte[] decode = Base64.decode(toUnGzip);
        return ZipUtil.unGzip(decode , CharsetUtil.CHARSET_UTF_8.name());
    }
}
  1. PS,发送端在数据发送前的处理流程如下(接收端互逆):

1.先对原始字符串签名,以保证签名忠实于原始内容;
2.然后压缩,以精简内容的尺寸,提高后续加密和传输的效率;
3.最后加密,保证数据安全。

猜你喜欢

转载自www.cnblogs.com/JaxYoun/p/12565027.html
今日推荐