首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >获取压缩包中的文本字符串。

获取压缩包中的文本字符串。

作者头像
崔笑颜
发布2020-06-08 17:05:03
1.7K0
发布2020-06-08 17:05:03
举报

业务如下

通过指定位置压缩包解析公钥,和密文,解析客户信息,不需要解压,那是我手动解压看效果的。 ps:中文可能会产生乱码,调一下编码。

QQ20200507-095449@2x
QQ20200507-095449@2x

代码如下

  public static void main(String[] args) throws Exception {
        new fileCheck().readZipFile("/Users/cuixiaoyan/Downloads/嘉士利科技有限公司.zip");
    }

    /**
     * 读取文件校验
     * @param filePath
     * @throws Exception
     */
    public String readZipFile(String filePath) throws Exception {
        //获取文件输入流
        FileInputStream input = new FileInputStream(filePath);
        //获取ZIP输入流(一定要指定字符集Charset.forName("GBK")否则会报java.lang.IllegalArgumentException: MALFORMED)
        ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(input), Charset.forName("GBK"));
        //定义ZipEntry置为null,避免由于重复调用zipInputStream.getNextEntry造成的不必要的问题
        ZipEntry ze = null;
        //公钥
        String publicKey = "";
        //密文
        String cipher = "";
        //循环遍历
        while ((ze = zipInputStream.getNextEntry()) != null) {
            //读取
            BufferedReader br = new BufferedReader(new InputStreamReader(zipInputStream, Charset.forName("GBK")));
            String line;
            while ((line = br.readLine()) != null) {
                if (ze.getName().equals("publicKey.txt")) {
                    publicKey = line += "\n";
                }
                if (ze.getName().equals("cipher.txt")) {
                    cipher += line += "\n";
                }
            }
        }
        //获取明文
        String clear = rSAUtilPbulicKey.decryptByPublicKey(publicKey, cipher);
        zipInputStream.closeEntry();
        input.close();
        return clear;
    }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-05-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 业务如下
  • 代码如下
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档