有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java 3DES_ECB解密

我想使用3DES_DEC_ECB对从第三方服务器接收到的数据进行解密 它们也提供了输出,但我无法复制相同的结果

Key = 5E8B6E1998F421204C6576544FE1A26B44FC775982D8CE2E
InputData = 13E37073120A47D119E82545CAAF1505E3E94E5E7D8B52F3
expectedoutput = 7CB842D42F4BA3C26C8297F5B26001FB5C9FD31532CA1CB7
techniqueActual output_data=3DES_DEC_ECB(Key, InputData)          

我尝试了下面的代码,但没有成功

import java.math.BigInteger;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.List;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.lang.StringUtils;
import util.HexString;

public class Util {
public static void main(String ...x) throws NoSuchAlgorithmException,         
NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException{
String keydata=  "5E8B6E1998F421204C6576544FE1A26B44FC775982D8CE2E";

String inputData = "13E37073120A47D119E82545CAAF1505E3E94E5E7D8B52F3";

byte[] keyByte = new BigInteger(keydata,16).toByteArray();

SecretKeySpec key=new SecretKeySpec(keyByte, "DESede");    

Cipher c = Cipher.getInstance("DESede/ECB/NoPadding");

c.init(Cipher.DECRYPT_MODE, key);

byte[] output = c.doFinal(inputData.getBytes());

String hexStr = HexString.bytesToHexString(output);
System.out.println("Decoded value : "+hexStr);

} }

共 (0) 个答案