通过指定位置压缩包解析公钥,和密文,解析客户信息,不需要解压,那是我手动解压看效果的。 ps:中文可能会产生乱码,调一下编码。
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;
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有