精华内容
下载资源
问答
  • GZIP解密(java)

    千次阅读 2019-06-20 16:56:35
    说明:前端GZIP压缩之后,后端使用JAVA解密 1.准备 需要一个jar: <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> &l...

    说明:前端GZIP压缩之后,后端使用JAVA解密

    1.准备

    需要一个jar:

            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
                <version>1.9</version>
            </dependency>
    
    

    需要一个工具类:

    package com.things.comm;
    
    import lombok.extern.log4j.Log4j2;
    import org.apache.commons.codec.CharEncoding;
    import org.apache.commons.codec.binary.Base64;
    
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.util.zip.GZIPInputStream;
    import java.util.zip.GZIPOutputStream;
    
    @Log4j2
    public class GZipUtil {
        /**
         * 压缩GZip
         *
         * @return String
         */
        public static String gZip(String input) {
            byte[] bytes = null;
            GZIPOutputStream gzip = null;
            ByteArrayOutputStream bos = null;
            try {
                bos = new ByteArrayOutputStream();
                gzip = new GZIPOutputStream(bos);
                gzip.write(input.getBytes(CharEncoding.UTF_8));
                gzip.finish();
                gzip.close();
                bytes = bos.toByteArray();
                bos.close();
            } catch (Exception e) {
                log.error("压缩出错:", e);
            } finally {
                try {
                    if (gzip != null)
                        gzip.close();
                    if (bos != null)
                        bos.close();
                } catch (final IOException ioe) {
                    log.error("压缩出错:", ioe);
                }
            }
            return Base64.encodeBase64String(bytes);
        }
    
        /**
         * 解压GZip
         *
         * @return String
         */
        public static String unGZip(String input) {
            byte[] bytes;
            String out = input;
            GZIPInputStream gzip = null;
            ByteArrayInputStream bis;
            ByteArrayOutputStream bos = null;
            try {
                bis = new ByteArrayInputStream(Base64.decodeBase64(input));
                gzip = new GZIPInputStream(bis);
                byte[] buf = new byte[1024];
                int num;
                bos = new ByteArrayOutputStream();
                while ((num = gzip.read(buf, 0, buf.length)) != -1) {
                    bos.write(buf, 0, num);
                }
                bytes = bos.toByteArray();
                out = new String(bytes, CharEncoding.UTF_8);
                gzip.close();
                bis.close();
                bos.flush();
                bos.close();
            } catch (Exception e) {
                log.error("解压出错:", e);
            } finally {
                try {
                    if (gzip != null)
                        gzip.close();
                    if (bos != null)
                        bos.close();
                } catch (final IOException ioe) {
                    log.error("解压出错:", ioe);
                }
            }
            return out;
        }
    }
    
    

    2.实现

    实现非常简单,直接贴代码。

    仅仅转换到json字符串,后面转换对象或者别的怎么用就随便搞了。

    package com.things.comm;
    
    import java.io.UnsupportedEncodingException;
    import java.net.URLDecoder;
    
    import static com.things.comm.GZipUtil.unGZip;
    
    /**
     * @Description:
     * @ClassName:van
     * @Author:Player
     * @Date:2019-06-13 14:03
     **/
    public class van {
    
        public static void main(String[] args) throws UnsupportedEncodingException {
            String json="H4sIAAAAAAAAA+1cWXPbOBL+Lfugmt2HuHhTfJTkOEmVc1Ti3ezbFESCEtYQqSKh2MqvH/AAiIYk8zDjkbKOKioTR7MvfN0NkJr484ll/cBZTtKE/zWxZ/zbNK+MK6O4tBb8O19jzPK6t5wweetO5v5k5k7eOpP59SRYTN5OJzNzMpua6rgEbbCk2japvFeEY7Sj8G5hSt9jFOHsa/rwHpPVmlW9llHNyYrmon+R0u8kYuuq21G7lVnmlW1XPSEYbxrGxL+WcxbpLhFTLDl+t0mUDrPuQCEjPzBnT1BSmzlXNZmqla2x1Mqhlj7HMQmx1Ec5mFNIs64zlii8X2WcxwiYAtU8uG4toXa90q6XzbVQSkPZ6kLZNiFl24CU7UbdDD+yLtwagCKkB6l14dCbAnJTB9AzDU9SRGGIk04cBlBoU1enaWtEu6nSh1QtSNUJNKJ2B6KmBy0vr5fNNaTqDPAnM7BOWKmi6fa3k2lqhgp0Q3ldxBdrV1D1bUDVNyXR9X6LM0qS+w5kofRBoHHaWD9OKU0fcPS+B3HTCQB5XyPPFcPJS7Y5JpJkdZMKtOLf1zhZ/ZcgDvXGrYDEikQa7U+MtCTFCDGksllc36ElBWhmnrz4gehOCQfWzefZNWL4n47tBP6/+L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SFSdcTLS9Mup6YaZyxcINg8vwF6omM5y9QTzA8f4F64t/5C9QT8s5foHaUm1h2HIe+8g7zoSx8TBAahuG9rAhzFHVi3yo+T7MfIz9qtcAypdFzmNff8qgf9tR58ePiI2cpbzA0jzZor4U8m5LyHsmzaakvnjyDGDD1AtFwR+VWfpvJkVt8xlx9L2R7Oy4+xxTj9bR9d0rttu9Oq4PtuxCDtl/j8J6rfIGpcsp8zPjNa06QQLrZoOfMNCbuvDppHEJjl2U4CffPnNyXh6Mwp6074OqEIUrC8VH67eOWogSxNCukqLZF2ldw6OG4LebwgGO+dNh8l6YtQafDO4V6fv0E4FjGWb5QeGxtn6iHlAXuHl/g76vfQpjUL3G9lGpN/8q+TOU6wSDtthRMI2t3rEj54tq1j2rXatNuS/V2Jto9wXx7pVbVAWHw1C5OHd39X18HvKbSg1PpD8l21xKCW7KITsXS+DZ+CSAovXxqKG8Tt+entyQpX6nvkKCKO+BlED69joKweHT0l+sYCPIJ7xh4kvMpEQow6Lscl1bxGWM5dqfUvhy70+rgPV2IQaWn1TNoY+xiaKXVmVayfW3dndJzKtkBtu5CDP4Y4I71wF4w9QvOwvrnOV6s9HA0/9B+lezQT+p8Ij8OL3fihw2eJcDfsVlzMvIMK4OecNvxa64TQesuZW1I35YFxIbx0hHqO8qSKmFt30fo7Utr5bd96geU237u54icv/0PAB0LYZXwr9Y4B2sc/wWu38Es1ctHzUsN6vunv5vdrNpu5fsefwHEztjVCVoAAA==";
            System.out.println(URLDecoder.decode(unGZip(json), "utf-8"));
        }
    }
    
    
    展开全文
  • gzip解密用什么组件?

    2013-07-01 21:22:42
    浏览器gzip数据解密用的是什么组件? 如何写代码调用解密呢?网上找的一段代码返回数据一多的话就容易内存错误 最好不要调用第3方组件,带个组件很麻烦[img=...
  • GZIP加密解密解压缩工具示例代码 1. 基于LZ77算法通过“滑动窗口”的方法对数据上报文件进行压缩处理; 2. 对得到的数据文件的结果再使用Huffman编码的方法进行压缩。 通过国密SM4加密解密
  • 加密: def encode_info(info): import base64 import gzip from cStringIO import StringIO ... f=gzip.GzipFile(mode="wb", fileobj=buf) f.write(puredata) f.close() info = buf.getvalue() info = base

    加密:

    def encode_info(info):
        import base64
        import gzip
        from cStringIO import StringIO
        puredata = info
        buf=StringIO()
        f=gzip.GzipFile(mode="wb", fileobj=buf)
        f.write(puredata)
        f.close()
        info = buf.getvalue()
        info = base64.b64encode(info)
        return info
    

    解密:

    echo "加密字符串" | base64 -d | gzip -d
    
    展开全文
  • crypto-js 和 pako实现数据加密, 解密
  • 主要介绍了vue项目中 使用 pako.js 解密 gzip加密字符串 的方法,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
  • 网上相关资源多半零碎不可用,详细整理了下的文件Gzip压缩后进行AES加密,同时反向解密解压缩。java代码和需要的jar包亲测可用!!
  • } } } } // base64转码为string /* * 将压缩并Base64后的字符串进行解密解压 * @param compressedStr 待解密解压字符串 * @return */ public static final String unzipString(String compressedStr) { if ...
    import java.io.*;
    import java.util.zip.*;
    import org.apache.commons.codec.binary.Base64;
    import sun.misc.BASE64Decoder;
    import sun.misc.BASE64Encoder;
    
    
    public class Base64GzipUtils {
    
        public static File base64ToFile(String base64) {
            if(base64==null||"".equals(base64)) {
                return null;
            }
            byte[] buff=new Base64().decode(base64.getBytes());
            File file=null;
            FileOutputStream fout=null;
            try {
                file = File.createTempFile("tmp", ".pdf",new File("D://"));
                fout=new FileOutputStream(file);
                fout.write(buff);
                fout.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                if(fout!=null) {
                    try {
                        fout.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return file;
        }
        /**
         * 将字符串压缩后Base64
         * @param primStr 待加压加密函数
         * @return
         */
        public static String zipString(String primStr) {
            if (primStr == null || primStr.length() == 0) {
                return primStr;
            }
            ByteArrayOutputStream out = null;
            ZipOutputStream zout = null;
            try{
                out = new ByteArrayOutputStream();
                zout = new ZipOutputStream(out);
                zout.putNextEntry(new ZipEntry("0"));
                zout.write(primStr.getBytes("gbk"));
                zout.closeEntry();
                return new BASE64Encoder().encode(out.toByteArray());
            } catch (IOException e) {
                return null;
            } finally {
                if (zout != null) {
                    try {
                        zout.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    //	base64转码为string
    
        /*
         * 将压缩并Base64后的字符串进行解密解压
         * @param compressedStr 待解密解压字符串
         * @return
         */
        public static final String unzipString(String compressedStr) {
            if (compressedStr == null) {
                return null;
            }
            ByteArrayOutputStream out = null;
            ByteArrayInputStream in = null;
            ZipInputStream zin = null;
            String decompressed = null;
            try {
                byte[] compressed = new BASE64Decoder().decodeBuffer(compressedStr);
                out = new ByteArrayOutputStream();
                in = new ByteArrayInputStream(compressed);
                zin = new ZipInputStream(in);
                zin.getNextEntry();
                byte[] buffer = new byte[1024];
                int offset = -1;
                while((offset = zin.read(buffer)) != -1) {
                    out.write(buffer, 0, offset);
                }
                decompressed = out.toString("gbk");
            } catch (IOException e) {
                decompressed = null;
            } finally {
                if (zin != null) {
                    try {
                        zin.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return decompressed;
        }
    
    
    
    
    
        public static String file2Base64(File file) {
            if(file==null) {
                return null;
            }
            String base64 = null;
            FileInputStream fin = null;
            try {
                fin = new FileInputStream(file);
                byte[] buff = new byte[fin.available()];
                fin.read(buff);
                base64 = new String(new Base64().encode(buff));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (fin != null) {
                    try {
                        fin.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return base64;
        }
        public static void main(String[] args) throws IOException {
            Base64GzipUtils zwz = new Base64GzipUtils();
            File file = new File("D://1.pdf");
            String str = file2Base64(file);
            System.out.println(str);
            String compString = zipString(str);
            System.out.println("========");
            System.out.println(compString);
            System.out.println(compString.length());
            String decompString = unzipString(compString);
    //        System.out.println(decompString);
            base64ToFile(decompString);
        }
    }

     

    展开全文
  • [root@127-0-0-1 nginx]# gzip -v access.log-20190328 access.log-20190328: 95.8% -- replaced with access.log-20190328.gz [root@127-0-0-1 nginx]#  replaced with :被替代 2、解压 方法...

    1、加密

    [root@127-0-0-1 nginx]# gzip  -v  access.log-20190328
      access.log-20190328:	 95.8% -- replaced with access.log-20190328.gz
    [root@127-0-0-1 nginx]# 
    

     replaced   with :被替代

    2、解压

         方法一:

    [root@127-0-0-1 nginx]# gzip -dv  /var/log/nginx/access.log-20190328.gz 
    access.log-20190328.gz:	 95.8% -- replaced with access.log-20190328
    [root@127-0-0-1 nginx]# 
    

      方法二:

    [root@127-0-0-1 nginx]# gunzip -v access.log-20190328.gz 
      access.log-20190328.gz:  95.8% -- replaced with access.log-20190328
    [root@127-0-0-1 nginx]# 
    

    3、版本

    [root@127-0-0-1 nginx]# gzip -V
    gzip 1.5
    Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
    Copyright (C) 1993 Jean-loup Gailly.
    This is free software.  You may redistribute copies of it under the terms of
    the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
    There is NO WARRANTY, to the extent permitted by law.
    
    Written by Jean-loup Gailly.
    [root@127-0-0-1 nginx]# 
    

    4、总结

        -v:显示指令执行过程;

        -d:解开压缩文件;

        -V:显示版本信息;

    转载于:https://www.cnblogs.com/Small-sunshine/p/11225958.html

    展开全文
  • 解密前消息 解密后: {“status”:“error”,“ts”:1605926619229,“id”:"",“err-code”:“bad-request”,“err-msg”:“1, is not json string”} 解密函数 let decode=function(websocket_msg){ return ...
  • * GZIP 解密 * * @param str * @return */ public static String decryptGZIP(String str) { if (str == null || str.length() == 0) { return null; } try { byte[] decode = str....
  • function unzip(b64Data) { var strData = atob(b64Data);... } atob()base64解密 charCodeAt() 方法可返回指定位置的字符的 Unicode 编码 fromCharCode() 可接受一个指定的 Unicode 值,然后返回一个字符串
  • java对象序列化、gzip压缩解压缩、加密解密
  • 实现base64+gzip+AES-ECB加密解密 # 本代码基于python3.6.1测试通过 import base64 from Crypto.Cipher import AES from io import StringIO import gzip ''' 采用AES对称加密算法 ''' # str不是16的倍数那就补足...
  • * 解密 * @param src byte[] * @return byte[] * @throws Exception */ public static byte [] decrypt ( byte [] src) throws Exception { IvParameterSpec iv = new IvParameterSpec...
  • 常见编码加密解密的基础用法 Base64编码 URL编码 GZIP AES加密 DES加密 RSA加密 public class MainActivity extends AppCompatActivity { private EditText mTextContent; private TextView mTxtResult; ...
  • 如果Header信息正确,就会返回经过GZip压缩的数据,这样直接获取网页数据的想法破灭了。  实际上.NET已经为我们封装好了GZip和Deflate加解压算法类,都位于 System.IO.Compression 命名空间内。...
  • str = window.btoa(pako.gzip(str, {to: "string" })) $( '#ciphertext' ).text(str); } function decode () { var encodedData = $( '#content' ).val(); var decodedData = window.atob(encodedData)...
  • 赶紧上百度找了一下资料,通过一篇文章(原文在底部)发现有个js库可以解密,就下载轻松解密了 实现代码 poko.js可至Github下载 https://github.com/nodeca/pako or npm install pako 1 imp...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 8,592
精华内容 3,436
关键字:

gzip解密