gpt4 book ai didi

java - 关于3DES的ECB的加密算法

转载 作者:行者123 更新时间:2023-12-02 07:14:25 25 4
gpt4 key购买 nike

数据将被加密:5140000000080401AEBFFFFFFFF7FBFE

key 是:00000000000000000000000000000000

最终结果:DBBE8A87A4E37D95B5EDDD2BE6A4151F

//SecretKey to save data
private SecretKey desKey;

//Complete encryption and decryption work
private Cipher c;

//Save encryption results
private byte[] cipherResultByte;

private final static String Algorithm = "DESede/ECB/NoPadding";//Encryption method/operation mode

private static DESedeKeySpec dks;

private static SecretKeyFactory keyFactory;

public DESeseTest02() {

Security.addProvider(new com.sun.crypto.provider.SunJCE());

try {

dks = new DESedeKeySpec("00000000000000000000000000000000".getBytes());

keyFactory = SecretKeyFactory.getInstance("DESede");


//Generate key
desKey=keyFactory.generateSecret(dks);


//Generate Cipher object, specify its support DES algorithm
c=Cipher.getInstance(Algorithm);

} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (InvalidKeySpecException e) {
e.printStackTrace();
}
}


public byte[] createEncryptor(byte[] b){

try {

// System.out.println(str);
//根据密钥,对Cipher进行初使化,DECRYPT_MODE加密模式
c.init(Cipher.ENCRYPT_MODE, desKey);

// byte[] input=str.getBytes();
// System.out.println(input.length);

//Encryption, the results will be preserved
cipherResultByte=c.doFinal(b);

} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return cipherResultByte;
}

但结果并不符合预期,为什么?任何人的帮助将不胜感激。

最佳答案

替换

"00000000000000000000000000000000".getBytes() 

new byte[34]

"0".getBytes() 与 new byte[] 不同{0}

关于java - 关于3DES的ECB的加密算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15103237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com