English 中文(简体)
Java AES 加密——可进行加密[复制]
原标题:Java AES decryption - can t decrypt string [duplicate]
This question already has an answer here:
Closed 11 years ago.

Possible Duplicate:
Java AES Encrypt Entire String

我已陷入一个小问题。 出于某种原因,我可以采用我对其加以加密的同样方法,对一些护卫进行加密。 例如,使用该编码进行加密的Im:

        SecretKeySpec key = new SecretKeySpec(salt.getBytes(), "AES");
    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE");
    cipher.init(Cipher.DECRYPT_MODE, key);
    String result = new String(cipher.doFinal(message));

    System.out.println("Decrypted:" + result);

Anyway, when the salt is "1231231231231231" and the message that im trying to decrypt is "read". I get this error:

Exception in thread "main" javax.crypto.BadPaddingException: Given final block not properly padded

But the encryptor (which works the same way) says the encrypted value is

I¡?Þd↨Ú#à, 7êLO* 

我如何确定这一点,或避免用户对此类描述的投入? Thansk

最佳回答

解决办法:不将其储存在地体内。

您对<代码>Cipher.doFinal的号召应存放在byte(byte [)上,您对加密工作的投入也应成为byte阵列。 如果您重新采用<条码> 输入,则使用<条码>。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签