package com.alex.security;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.spec.KeySpec;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
public class PBESecretKeyTest {
public static void main(String[] args) throws Exception{
//定义需要进行加密的数据
String data ="alex zhuang";
System.out.println("加密前的数据为:"+data);
//对数据进行加密
secretEncrypt(data);
//对数据进行解密
secretDecrypt("D:/PBencrypted.data","D:/PBsecret.key");
}
public static void secretEncrypt(String data) throws Exception{
//使用PBEWithMD5AndDES算法获取Cipher实例
Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
//初始化密钥
SecretKeyFactory keyFactory =