(三重DES)Qt Creator中的DESede / CBC / PKCS5Padding加密和解密

时间:2018-08-20 12:22:46

标签: java c++ encryption qt5.10

我想在我尝试过的qt创建者代码中使用JAVA加密和解密逻辑,并搜索了很多内容,但成功实现了“ DES / CBC”加密和解密逻辑,但对我没有用,因为JAVA代码位于“ DESede / CBC / PKCS5Padding”三重DES逻辑。 JAVA CODE如下:

public static String initializationVector = "abhijeet";   
public static String key="XB13347FE570DC4FFB13647F";    

public String encryptText(String plainText) throws Exception {
    // ---- Use specified 3DES key and IV from other source --------------
    byte[] plaintext = plainText.getBytes();
    byte[] tdesKeyData = Config.key.getBytes();
    // byte[] myIV = initializationVector.getBytes();
    Cipher c3des = Cipher.getInstance("DESede/CBC/PKCS5Padding");
    SecretKeySpec myKey = new SecretKeySpec(tdesKeyData, "DESede");
    IvParameterSpec ivspec = new IvParameterSpec(Config.initializationVector.getBytes());
    c3des.init(Cipher.ENCRYPT_MODE, myKey, ivspec);
    byte[] cipherText = c3des.doFinal(plaintext);
    return new BASE64Encoder().encode(cipherText);
}

public static String decryptText(String cipherText) throws Exception {
    byte[] encData = new BASE64Decoder().decodeBuffer(cipherText);
    Cipher decipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
    byte[] tdesKeyData = Config.key.getBytes();
    SecretKeySpec myKey = new SecretKeySpec(tdesKeyData, "DESede");
    IvParameterSpec ivspec = new IvParameterSpec(Config.initializationVector.getBytes());
    decipher.init(Cipher.DECRYPT_MODE, myKey, ivspec);
    byte[] plainText = decipher.doFinal(encData);
    return new String(plainText);
}

示例:

输入字符串-“ Hello” 加密后输出字符串-“ c13FZpr4odg =”

请提供与我在这里停留的相同的帮助

0 个答案:

没有答案