0

我需要加密用户名和密码并对它们进行编码并通过 SOAP 标头发送。我使用DES算法加密明文`

String key = "qwer1234qwetr123wqw";
        String x = "sadgsagd:%%^%ghsagdh";
        byte[] keyBytes = new byte[1024];
        byte[] plaintext = x.getBytes();
        byte[] tdesKeyData = key.getBytes();

    Cipher c3des = Cipher.getInstance("DESede/CBC/PKCS5Padding");
    SecretKeySpec myKey = new SecretKeySpec(tdesKeyData, "DESede");
    IvParameterSpec ivspec = new IvParameterSpec(keyBytes);

    c3des.init(Cipher.ENCRYPT_MODE, myKey, ivspec);
    byte[] cipherText = c3des.doFinal(plaintext);
    int hash = Base64.encode(cipherText).hashCode();

    return Base64.encode(cipherText);`

在运行时我得到一个异常:

javax.crypto.BadPaddingException:给定

4

1 回答 1

0

如果你使用的是字节缓冲区64,我可能太长了,把它改成,32或者像这样使用lengthfilebyte[] buffer = new byte[(int)new File("data").length()];

这样做后我的问题得到解决..

于 2013-04-24T04:55:40.533 回答