关于DES解密
天地一棵树 2010-11-30 05:39:39 /*基于DES的解密算法*/
import java.io.FileInputStream;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
/**
*
*/
/**
* @author use
*
*/
public class SDec {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
FileInputStream f=new FileInputStream("SEnc.dat");
int num=f.available();
byte[] ctext=new byte[num];
f.read(ctext);
FileInputStream f2=new FileInputStream("keykb1.dat");
int num2=f2.available();
byte[]keykb=new byte[num2];
f2.read(keykb);
SecretKeySpec k=new SecretKeySpec(keykb,"DESede");
Cipher cp=Cipher.getInstance("DESede");
cp.init(Cipher.DECRYPT_MODE, k);
byte[]ptext=cp.doFinal(ctext);
String p=new String (ptext,"UTF8");
System.out.println(p);
}
}
错误:
Exception in thread "main" java.security.InvalidKeyException: Invalid key length: 40 bytes
at com.sun.crypto.provider.DESedeCipher.engineGetKeySize(DashoA13*..)
at javax.crypto.Cipher.b(DashoA13*..)
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
at SDec.main(SDec.java:31)