我下载了一个3des加密的工具,得到如下结果:
原文:06111111FFFFFFFF
密钥:11111111111111111111111111111111
密文:C1335C0C5EC48958
这个也是我需要的结果,但是我用java始终没有得到这样的结果。求相关java代码,紧急,谢谢
------解决方案--------------------
我用java写的测试,生成的结果前面的8字节与你相同,只是多个8个字节,供参考:
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
public class TestDes {
private static final String Algorithm = "DESede";
public static byte[] encryptMode(byte[] keybyte, byte[] src) {
try {
SecretKey deskey = new SecretKeySpec(keybyte, Algorithm);
Cipher c1 = Cipher.getInstance(Algorithm);
c1.init(Cipher.ENCRYPT_MODE, deskey);
return c1.doFinal(src);
} catch (java.security.NoSuchAlgorithmException e1) {
e1.printStackTrace();
} catch (javax.crypto.NoSuchPaddingException e2) {
e2.printStackTrace();
} catch (java.lang.Exception e3) {
e3.printStackTrace();
}
return null;
}
public static byte[] decryptMode(byte[] keybyte, byte[] src) {
try {
SecretKey deskey = new SecretKeySpec(keybyte, Algorithm);
Cipher c1 = Cipher.getInstance(Algorithm);
c1.init(Cipher.DECRYPT_MODE, deskey);
return c1.doFinal(src);
} catch (java.security.NoSuchAlgorithmException e1) {
e1.printStackTrace();
} catch (javax.crypto.NoSuchPaddingException e2) {
e2.printStackTrace();
} catch (java.lang.Exception e3) {
e3.printStackTrace();