您的位置:首页 > 编程语言 > Java开发

关于绿盾解密功能java代码。

2015-10-23 11:45 351 查看
其实也就是个文件夹复制功能,解密前提需要绿盾支持该编程工具,在编程工具中运行该代码(其中原理自己去琢磨咯)。

<span style="font-size:14px;">package com.core;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.text.DecimalFormat;

/**
* @Classname: Decrypt
* @Description: TODO
* @Author: chenn_xu@sina.cn
* @Date: 2015年10月16日 上午11:04:32
* @Version:V1.0
*/
public class Decrypt {

//待解密的文件夹路径
private static String rootFolderPath = getFullpath("E:","decrypt_dev");
//待解密文件夹路径中的文件夹
private static String replace = "decrypt_new";
//被替换的文件夹
private static String beReplaced = "decrypt_dev";

//解密文件数
private static Integer fileCount = 0;
//解密文件大小
private static Long fileSize = new Long(0);

public static void main(String[] args) {
try {
Long startTime = System.currentTimeMillis();
decryptFolder(new File(rootFolderPath));
System.out.println("------------------------------------------------------------------------------------------------");
System.out.print("解密完成,共计耗时:"+new DecimalFormat("0.00").format((double)(System.currentTimeMillis()-startTime)/1000)+"s");
System.out.print("\t共计文件:"+fileCount+"个");
System.out.print("\t共计文件大小:"+new DecimalFormat(",##0.00").format((double)fileSize/1024/1024/1024)+"GB");
System.out.print(" = "+new DecimalFormat(",##0.00").format((double)fileSize/1024/1024)+"mb");
System.out.println(" = "+new DecimalFormat(",##0.00").format((double)fileSize/1024)+"kb");
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* @Methodname: getFullpath
* @Discription: TODO 拼接完整的路径 根据操作系统拼接连接符
* @param dir 路径
* @return
*/
private static String getFullpath(String... dir){
StringBuffer fullPath = new StringBuffer("");
for (int i = 0; i < dir.length; i++) {
fullPath.append(dir[i]);
if (dir.length-1!=i) {
fullPath.append(File.separator);
}
}
return fullPath.toString();
}

/**
* @Methodname: decryptFolder
* @Discription: TODO 解密整个文件夹
* @param folder 文件夹
* @throws Exception
*/
private static void decryptFolder(File folder)throws Exception {
if (!folder.isDirectory()) {
return;
}
File[] files = folder.listFiles();
for (File file : files) {
if (file.isFile()) {
//进行解密操作
decryptFile(file);
fileCount ++;
fileSize += file.length();
continue ;
}
//创建文件夹
File childFolder =new File(getFullpath(folder.getPath(),file.getName()));
File newChilFolder =new File(childFolder.getPath().replaceFirst(beReplaced,replace));
if (newChilFolder.exists()) {
newChilFolder.delete();
}
newChilFolder.mkdir();
//进行递归
decryptFolder(childFolder);
}
}

private static void decryptFile(File file){
try {
File newFile = new File(file.getPath().replaceFirst(beReplaced,replace));
if (newFile.exists()) {
newFile.delete();
}
newFile.createNewFile();
FileOutputStream output = new FileOutputStream(newFile);
InputStream input = new FileInputStream(file);
int length = -1;
byte[] _byte = new byte[8000];
System.out.println(file.getPath());
int sum = input.available();
System.out.print("文件名:"+file.getPath());
System.out.print("\t文件大小:"+new DecimalFormat("0.00").format((double)file.length()/1024)+"kb");
System.out.print("\t已解密大小:"+new DecimalFormat("0.00").format((double)(file.length()-input.available())/1024)+"kb");
System.out.println("\t已解密比例:"+(sum==0?"100%":new DecimalFormat("0.00%").format((double)(sum-input.available())/sum))+"kb");
while ((length=input.read(_byte))!=-1) {
System.out.print("文件名:"+file.getPath());
System.out.print("\t文件大小:"+new DecimalFormat("0.00").format((double)file.length()/1024)+"kb");
System.out.print("\t已解密大小:"+new DecimalFormat("0.00").format((double)(file.leng
4000
th()-input.available())/1024)+"kb");
System.out.println("\t已解密比例:"+(sum==0?"100%":new DecimalFormat("0.00%").format((double)(sum-input.available())/sum)));
output.write(_byte, 0, length);
}
System.out.println();
input.close();
output.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: