`
szqfsx123
  • 浏览: 42421 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

DESede 加密解密测试

 
阅读更多
public class TestStream {

    private static final String KEY_CODE = "qwertyuiopadsfghjklzxcvbnm";
    public static void main(String[] args) throws Exception {
        System.out.println(KEY_CODE.length());
teste();
testd();
}

    public static void teste() throws Exception {
        String filePath = "C:\\Users\\Administrator\\Desktop\\新建文本文档.txt";
String filePathNew = "C:\\Users\\Administrator\\Desktop\\新建文本文档_new.txt";
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(1,getKey());
        byte[] fileBytes = StreamUtils.copyToByteArray(new FileInputStream(new File(filePath)));
        byte[] encodeBytes =cipher.doFinal(fileBytes);
StreamUtils.copy(encodeBytes,new FileOutputStream(new File(filePathNew)));
}

    public static void testd() throws Exception {
        String filePathNew = "C:\\Users\\Administrator\\Desktop\\新建文本文档_new.txt";
String filePathOld = "C:\\Users\\Administrator\\Desktop\\新建文本文档_old.txt";
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(2,getKey());
        byte[] fileBytes = StreamUtils.copyToByteArray(new FileInputStream(new File(filePathNew)));
        byte[] decodeBytes =cipher.doFinal(fileBytes);
StreamUtils.copy(decodeBytes,new FileOutputStream(new File(filePathOld)));
}

    public static Key getKey() throws Exception {
        SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("DESede");
DESedeKeySpec keySpec = new DESedeKeySpec(KEY_CODE.getBytes("UTF-8"));
SecretKey secretKey = secretKeyFactory.generateSecret(keySpec);
        return secretKey;
}
}



package demo;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;

import java.io.File;
import java.util.Collection;
import java.util.Objects;

public class BatchFileReName {

    public static void main(String[] args){
        listFiles();
}

    public static void listFiles(){
        String filePath = "G:\\workspace\\sdfkjsdlf";
File dirFile = new File(filePath);
Collection<File> listFiles = FileUtils.listFilesAndDirs(dirFile,DirectoryFileFilter.INSTANCE,DirectoryFileFilter.INSTANCE);
        int i=0;
        for (File file : listFiles) {
            if (Objects.equals(file.getName(),"sdlfkjsldf")){
                System.out.println("["+i+"]"+file.getName()+"--------"+file.getAbsolutePath()+"====parent----"+file.getParentFile().getAbsolutePath());
file.renameTo(new File(file.getParentFile().getAbsolutePath()+"\\lhl"));
}
            i++;
}
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics