import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
public class GenKey {
public static void main(String[] args){//生成密钥
//将密钥保存在文件中
try {
KeyGenerator keyGen = KeyGenerator.getInstance("DESede");
//初始化密钥生成器
keyGen.init(168);
//生成密钥
SecretKey key = keyGen.generateKey(); //以二进制文件流形式存储
//将密钥保存在文件中
FileOutputStream f = new FileOutputStream("key3.dat");
ObjectOutputStream b = new ObjectOutputStream(f);
b.writeObject(key);