文件加密解密算法(Java源码)
java,file,算法,加密解密,java源码
package com.crypto.encrypt;
import java.security.SecureRandom;
import java.io.*;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.Cipher;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import java.lang.reflect.Constructor;
import java.security.spec.KeySpec;
import java.lang.reflect.InvocationTargetException;
public class EncryptData {
private String keyfile=null;
public EncryptData() {
}
public EncryptData(String keyfile) {
this.keyfile=keyfile;
}
/**
* 加密文件
* @param filename String 源路径
* @param filenamekey String 加密后的路径
*/
public void createEncryptData(String filename,String filenamekey) throws
IllegalStateException, IllegalBlockSizeException, BadPaddingException,
NoSuchPaddingException, InvalidKeySpecException, NoSuchAlgorithmException,
InvalidKeyException, IOException, InstantiationException,
IllegalAccessException, IllegalArgumentException,
InvocationTargetException, NoSuchMethodException, SecurityException,
ClassNotFoundException, IllegalStateException, IllegalBlockSizeException,
BadPaddingException, NoSuchPaddingException, InvalidKeySpecException,
NoSuchAlgorithmException, InvalidKeyException, IOException {
//验证keyfile
if(keyfile==null || keyfile.equals(""))
{
throw new NullPointerException("无效的key文件路径");
}
encryptData(filename,filenamekey);
}
/**
* 加密类文件
* @param filename String 原始的类文件
* @param encryptfile String 加密后的类文件
* @throws IOException
* @throws InvalidKeyException
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
* @throws NoSuchPaddingException
* @thro
1